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
Generic arrow function in Typescript cause esbuild error #3883
Comments
I had the same problem with other build systems. This is not a problem with vitejs, but rather the typescript compiler Typescript on the other hand cannot solve this problem (in tsx files), because you could always be using the XML syntax and the compiler cannot distinguish between them. https://stackoverflow.com/a/37687827 in tsx files you have to always use the |
The compiler can distinguish between them as long as you add some "hint". In my case, the hint is the comma:
But the comma seems to get lost before the code reaches esbuild (in the log output the comma doesn't show up anymore). I am sure that this problem lies within the vite dev server pipeline as it works without a problem with, e.g., create-react-app. Even |
the plugin
vite/packages/plugin-react-refresh/index.js Line 104 in bb095db
|
@OneNail Can you please help me understand what exactly is at fault here? Is it the typescript plugin of babel? Or is there something wrong with how it is used within '@vitejs/plugin-react-refresh'? If the error lies outside of vitejs I would file a bug report there. |
const doSomething2 = <T,>(value: T): T => {
return value;
}; const { transformSync } = require("@babel/core");
const result = transformSync(code, {
parserOpts: {
plugins: [ "typescript" ]
},
}); the const doSomething2 = <T>(value: T): T => {\n return value;\n}; babel's transform |
Something very similar
The code above results the following error: The code below works
|
The underlying esbuild upgrade caused a couple of new errors to surface: - Dependency type and Dependency view name conflict - <T, > not parsing correctly in the generic function definition The second error appears to be a bug: vitejs/vite#3883
EDIT: my bad the issue is in the generator package and yes there is an issue filed: babel/babel#13778 that is coming from #4949 It's my third attempt to convert a large codebase to Vite and I'm glad I finally found this issue that put me on the right track. @OneNail @sodatea from my understanding this is an issue with the TS parser in Babel. Did any of you file an issue with Babel for this? |
The issue was fixed in babel@7.16.8 (PR babel/babel#14113). #4949 might also be closed |
Describe the bug
The usage of
<T, >
in .tsx files causes an error.For example, this causes an error:
const doSomething = <T, >(value: T): T => { return value; }
While this works:
function doSomething<T>(value: T): T { return value; }
@n1ru4l reported this issue in the esbuild project but they determined that this is not an esbuild problem: evanw/esbuild#934
Reproduction
https://github.com/yankydoo/vite-generic-arrow-function-repro
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: yarn
Logs
Error message in the browser when running
vite
:Here you can see that the comma is missing - maybe some preprocessing step strips it away?
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: