Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do I have to specify the target directly in the esbuild option, apart from the target loaded in tsconfig? #2391

Closed
tenzyu opened this issue Jul 15, 2022 · 2 comments

Comments

@tenzyu
Copy link

tenzyu commented Jul 15, 2022

Q. Do I have to specify the target directly in the esbuild option, apart from the target loaded in tsconfig?

From the behavior, I may have found a bug.

I can't find the specific cause, right away, so I have a sample to reproduce for illustrative purposes.
https://github.com/tenzyu/20220715-esbuild-not-transforming

This is about the try-catch syntax from es2019.

The output-1.js only specified tsconfig with target. } catch {, which is an error in es2015 and others.
output-2.js specified not only tsconfig, but also the target of the API. It is converted to } catch (t3) {, which works fine.

The actual build code is here.

I tried two things before making this sample.
Directly in input.ts try { ... } catch { ... } directly in input.ts, no problem.
In module/try-catch.ts
export const tryCatch = try { ... } catch { ... }
in module/try-catch.ts and imported and used in input.ts, there was no problem.
It probably happens when using libraries.

Before I try any further, I thought that specifying the target directly, rather than just the target in tsconfig, might be what the following quote is about, so I asked the question first.

By default esbuild takes advantage of modern JavaScript features to make your code smaller. For example, a === undefined || a === null ? 1 : a could be minified to a ? If you do not want esbuild to take advantage of modern JavaScript features when minifying, you should use an older language target such as --target=es6. - https://esbuild.github.io/api/#minify-considerations

Thanks.

@evanw
Copy link
Owner

evanw commented Jul 16, 2022

This used to work, but was changed on request: #1355. The rationale was that the workflow that esbuild's TypeScript support is replacing is first running tsc to convert TypeScript into JavaScript followed by running a bundler to bundle the JavaScript together. In that workflow, the tsconfig.json file is only relevant for your TypeScript code and not the code of your dependencies inside of node_modules because you only run tsc on your code, not on your dependencies. Arguably esbuild should work the same way, which is why esbuild deliberately ignores your tsconfig.json file for your dependencies inside of node_modules.

@tenzyu
Copy link
Author

tenzyu commented Jul 16, 2022

Wow the explanation is very clear!

I agreed, Thank you!! 😆

@tenzyu tenzyu closed this as completed Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants