-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
The execution results of decorator code compiled by esbuild and compiled by tsc are inconsistent #3911
Comments
I can't reproduce this, sorry. Here's the live link to your code example. As you can see in the live link, the command line you're using doesn't tell esbuild to transform decorators at all, so your reproduction instructions result in the output code still containing decorators. In that case the behavior of decorators is up to the JavaScript VM that you use to run them, which has nothing to do with esbuild. If you want esbuild to transform decorators, then you'll have to tell it to do so. You can do that by setting I'm guessing what's happening here is that you actually have a |
Thanks for your reply. Sorry, my English is a little poor. I am Chinese, so what I say below may not be accurate. Please forgive me. The tsconfig in my project does contain the configuration.
So I successfully got the output When I use tsc to compile ts code, I set experimentalDecorators to false and get the correct result 666. Please forgive me for my poor English, the following content may contain errors I understand that the proposal says that when experimentalDecorators is false, the decorator should be automatically converted. But esbuild does not convert it. I think there may be something wrong with my understanding. Please help me solve it. I want esbuild to output the correct result 666. How can I do it? Does esbuild support the implementation of the latest tc39 proposal? And the two input parameters of the decorator are, ES Decorators now accept exactly two arguments: target and context: target — A value representing the element being decorated context — An object containing additional context information about the decorated element |
Thank you for your reply, but I still have some questions. I forgot to reply you above. The content is all above. Please check it out. |
Thank you, my problem was solved, I set target=es2020, and then converted successfully But I still have a small question, that is, when tsc compiles, decorators can be successfully compiled without any parameters but esbuild needs to set target=es2020, and tc39 states that when experimentalDecorators is set to false, it should be automatically converted. Is it that the default target version of tsc is inconsistent with the default target version of esbuild? |
I am using vite to develop an application. Vite is based on esbuild packaging. However, since I just used esbuild to get the correct result from the link, but my vite result is still wrong, I thought it was a problem with vite. Then I debugged the source code of vite. At the end of the debugging, I found that the problem came from the configuration item loader=ts of esbuild, and https://esbuild.github.io/content-types/#tsconfig-json
If I use a decorator This rule is too hidden, and it does not use the configuration in tsconfig.json, so additional configuration is required.
This problem makes me sad. Can this rule be made better? For example, tsconfigRaw will replace compilerOptions with the configuration in tsconfig.json by default |
This is a problem with vite, not related to esbuild, so close the question, thank you very much for your answer |
main.ts
excute esbuild

npx esbuild main.ts --bundle --platform=node --outfile=out.js; node out.js
get console undefined
esbuild version 0.21.5
excute tsc compiler
get result success
Related issues
vitejs/vite#18101 (comment)
The text was updated successfully, but these errors were encountered: