-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] Problems with typescript decorators (Unexpected token @
.)
#2951
Comments
@
.)@
.)
Started looking into this a little and noticed adding However, it seems the decorator never gets transpiled, resulting in a runtime error. It's not clear to me if Qwik's core is doing the actual transpiring here or if this is left up to Vite. Hopefully someone smarter than me could point me in the right direction. I'd be happy to continue looking into this. |
Yeah I think anything other than the parser option above may be out of Qwik's responsibilities. (Happy to get a PR going to enable this if it seems reasonable to the maintainers) After digging a litter deeper, I was able to configure the babel vite plugin to just parse the decorators with the following setup: import { defineConfig } from "vite";
import { qwikVite } from "@builder.io/qwik/optimizer";
import { qwikCity } from "@builder.io/qwik-city/vite";
import babel from "vite-plugin-babel";
export default defineConfig(() => {
return {
plugins: [
qwikCity(),
qwikVite(),
babel({
babelConfig: {
presets: [["@babel/preset-typescript"]],
plugins: [["@babel/plugin-proposal-decorators", { version: "2023-01" }]],
},
filter: /\.ts?$/,
}),
],
};
}); |
I do have this problem too, and even this approach doesn't work. My error message is different:
|
@saeedhbi This approach is what is needed by the end user in addition to the Qwik parser understanding decorators. I don't currently know of a way to get decorators loading in Qwik until this issue is resolved. |
I could handle the decorators by changing the order of babel configurations. But also, I'm not sure why but it didn't work with The {
plugins: [
tsconfigpath(),
react({
babel: {
babelrc: false,
configFile: false,
plugins: [
["@babel/plugin-transform-class-static-block"],
["@babel/plugin-proposal-decorators", { version: "legacy" }],
["@babel/plugin-proposal-class-properties"],
],
},
}),
qwikVite(),
qwikCity()
]
}` |
i just tried this way but i got the same error |
Hi @r1n0x , thanks for opening this issue, did you solve this specific problem with the @ ? |
I think there are two parts:
|
Hi,
For me, modifying
|
FYI I'm updating the optimizer and it will include decorator support but it's not done yet. |
Which component is affected?
Qwik Rollup / Vite plugin
Describe the bug
So I wanted to build classic website like in PHP/NextJS, no edge functions etc. and I wanted to use TypeORM and I was meet with error which said:
[plugin:vite-plugin-qwik] Unexpected token `@`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp, ` for template literal, (, or an identifier
which I guess is because of TypeORM uses decorators,At first after some googling internet said it may be because Vite compiles to esbuild and it supposedly doesn't support decorators, but after trying it in normal Vite it works smoothly so I think problem is in the plugin.
Error message while trying to execute class method. (reproducing code has this)
Error message while having a class decorator (straight from TypeORM).
The funny thing is that is clearly says @ symbol should be accepted XD
Reproduction
https://github.com/r1n0x/qwik-issue
Steps to reproduce
Working example in qwik (installed using npm create qwik@latest today):
Try doing this without commenting 10th line and it breaks with said error.
I've attached a normal vite as comparison too, which works normally with or without the decorator (installed using npm create vite@latest today):
System Info
Additional Information
Tried googling but Qwik is pretty new and so I didn't find anything and normal vite works sooo... I'm out of ideas! Hope you guys can help!
The text was updated successfully, but these errors were encountered: