Closed hybridherbst closed 1 year ago
Start a new pull request in StackBlitz Codeflow.
I've read through the breaking changes in esbuild (https://github.com/evanw/esbuild/blob/main/CHANGELOG.md#0180:~:text=Prefer%20.js%20over%20.ts%20within%20node_modules%20(%233019)) and can just assume that something there affects this case...
me too
Same here. Here's the reproduction - https://codesandbox.io/p/sandbox/typescript-playground-export-forked-x2lj66?file=%2Fpackage.json%3A6%2C19;
Steps to reproduce
yarn test
. It throws following error
If you change the resolution of vite
to 4.3.9
and then run yarn install && yarn test
on the console, error goes away and test passes.
Specifying "experimentalDecorators": true
in tsconfig.json
(compilerOptions
) helps
Specifying
"experimentalDecorators": true
intsconfig.json
(compilerOptions
) helps
No solution to the problem.
Likely related to https://github.com/vitejs/vite/pull/13525, maybe we need to set experimentalDecorators: true
by default for now.
starting esbuild 0.18.5 ECMA decorators
have been supported. So this may require a bump in the supported esbuild
version for vite. In the meantime, we can live with experimentalDecorators: true
experimentalDecorators: true
did not solve the problem
We also had experimentalDecorators: true
already on (since we're using decorators) and the issue happens with that.
We also had
experimentalDecorators: true
already on (since we're using decorators) and the issue happens with that.
same as you, we already set it in tsconfig.json, still throw err
Another way to make sure if experimentalDecorators
is really set is with this in vite.config.js
:
export default {
esbuild: {
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true,
},
},
},
}
It could be that your tsconfig isn't include
-ing the files that use decorators.
Same issue here, tsconfig is correct.
I also tried with the suggestion above adding it to vite.config.js without luck
The error doesnt happen when the package comes from npm - but it does reproduce with the package installed via a local file path
Can confirm this same issue in Aurelia projects. Enabling experimental decorators via tsconfig does not fix the problem.
Not working here either.
[ERROR] Parameter decorators only work when experimental decorators are enabled
Already got "experimentalDecorators": true
. Using inversifyjs decorators
still exist
Can anyone share a repro? There's only one (https://github.com/vitejs/vite/issues/13736#issuecomment-1624716047) and that worked when I set "experimentalDecorators": true
. I'm thinking we can add that by default, but I'm confused why it doesn't work for some others.
Can anyone share a repro? There's only one (#13736 (comment)) and that worked when I set
"experimentalDecorators": true
. I'm thinking we can add that by default, but I'm confused why it doesn't work for some others.
https://stackblitz.com/edit/au2-conventions-qvwece?file=tsconfig.json
I just had a case where decorators silently failed for fields (no invocation of the decorator function!)
but the error started to showup when I added a method decorator. After downgrading to vite <= 4.3.9
the error disappeared and it worked as expected.
Took me a while to find this since I didnt get any errors
stackblitz.com/edit/au2-conventions-qvwece?file=tsconfig.json
@CollinHerber Thanks! I was able to track down another spot to fix, will handle that in the PR too. As a workaround, you can set this in your vite.config.js
:
optimizeDeps: {
esbuildOptions: {
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true
}
}
}
}
In my case, Vite 4.4.x fails with the following declaration (but Vite 3.3.9 succeeds):
@themedComponent
@trackWebPage<StudyoAnalyticsPage>('Preparing')
@inject(
StudyoWebServiceKeys.viewModelFactory,
StudyoWebServiceKeys.localizationService,
StudyoWebServiceKeys.reactRouterRouteService
)
@observer
export class PreparingSchoolScreen extends React.Component<PreparingSchoolScreenProps> {
The error is:
I do have experimentalDecorators
set to true
in my tsconfig.
Update
Setting experimentalDecorators
to true
in vite.config.js
as described above solved it for me!
Update 2
Instead of setting experimentalDecorators
in vite.config.js
, I simply configured it to use my tsconfig.json
(which already sets experimentalDecorators
:
optimizeDeps: {
esbuildOptions: {
tsconfig: 'tsconfig.json'
}
},
And it works.
As a workaround I found that if you're using Nuxt 3 you can give some tsconfig to esbuild which is used internally inside nitro.
export default defineNuxtConfig({
nitro: {
esbuild: {
options: {
target: "esnext",
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true,
emitDecoratorMetadata: true,
},
},
},
},
},
});
Describe the bug
I'm a bit at a loss at what's going on - in a project I have using vite 4.4.0 or 4.4.1 breaks decorators in TypeScript, but going back to 4.3.9 fixes the issue.
All I'm getting on 4.4.0 is
SyntaxError: Invalid character: '@'
(on some code on our end that uses decorators), while in 4.3.9 everything works.What is extra weird is that I can't reproduce the issue on StackBlitz even with the same setup / configs in place. I've included my tests so far nonetheless, as I can 100% reproduce the issue locally by switching between vite 4.4.0 and 4.3.9 as dependency.
Discord discussion: https://discord.com/channels/804011606160703521/804011606160703524/1126556878676168784
Reproduction
Tried to repro here but no luck so far: https://stackblitz.com/edit/vitejs-vite-ojnmgf?file=myPackage%2FmyCode.ts
Steps to reproduce
No response
System Info
Used Package Manager
npm
Logs
Click to expand!
```shell SyntaxError: Invalid character: '@' ```Validations