Closed r1n0x closed 1 year ago
Started looking into this a little and noticed adding decorators: true
to the parser options allows the build to complete without error.
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?$/,
}),
],
};
});
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:
Error: Unexpected token @. Expected identifier, string literal, numeric literal or [ for the computed key
@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.
@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 vite-plugin-babel
plugin and it will work only with @vitejs/plugin-react
.
The @vitejs/plugin-react
plugin should be ordered before qwik
plugins. Like:
{
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()
]
}`
@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
vite-plugin-babel
plugin and it will work only with@vitejs/plugin-react
.The
@vitejs/plugin-react
plugin should be ordered beforeqwik
plugins. Like:{ 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:
decorators: true
as describe https://github.com/BuilderIO/qwik/issues/2951#issuecomment-1585794394Hi,
For me, modifying vite.config.ts
like this was enough:
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: {
plugins: [["@babel/plugin-proposal-decorators", { version: "2023-01" }]],
},
filter: /\.(ts|tsx)$/,
}),
],
};
});
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):
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!