-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 vite.build.target setting does not take effect in dev mode. #12655
Comments
I thought the issue could be resolved by specifying the target when running esbuild, so I investigated where esbuild is executed during As a result, I found that the output of transformWithEsbuild is used at the following location: astro/packages/astro/src/vite-plugin-astro/compile.ts Lines 39 to 41 in f13417b
As an experiment, I modified this part to 'target: "es2018"', and found that the decorators were transpiled, and the error no longer occurred during |
I would like to create a Pull Request to modify the above location (packages/astro/src/vite-plugin-astro/compile.ts) so that the value of |
You need to use |
@bluwy Thank you for your response! I have also added the // astro.config.mjs
export default defineConfig({
vite: {
build: { target: 'es2018' },
esbuild: { target: 'es2018' }, // added
}
}); I have also added this to the example. |
@bluwy As you pointed out, it seems more appropriate to apply |
Is there a workaround for this? I upgraded from Astro 4 to 5.1 and I am hitting a similar/the same issue I am on Windows 10 with Node 22.12.0 + PNPM 9.15.1 |
@sebthom That error might indeed be the same issue. I don't have a simple workaround. |
@koyopro This didn't help in my case but I found out that the issue disappears in Astro 5 when I remove the usage of https://github.com/Dovias/astro-runtime-config in my project. |
@sebthom Now that you mention it, the fact that it doesn't reproduce on Astro 4 but does on 5.1 makes me think this might be a separate issue. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
The
vite.build.target
setting does not take effect in dev mode.I want to use the decorator feature introduced in TypeScript 5.0.
https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators
This new decorator feature is supported in esbuild 0.21.0 and above.
https://github.com/evanw/esbuild/releases/tag/v0.21.0
According to the esbuild documentation, by specifying a target value lower than "esnext" (such as "es2022"), decorators will be transformed and can be executed in Node.js.
https://esbuild.github.io/content-types/#javascript
In an Astro project, esbuild is executed via Vite, but by default, the target seems to be set to "esnext".
So, I added the following configuration to
astro.config.mjs
:This configuration works as expected when running
npm run build
, and the decorators are transformed.However, when running
npm run dev
, the decorators are not transformed, resulting in an "Invalid or unexpected token" error.(Incidentally, if the target is not specified, the decorators are not transformed even during
npm run build
, resulting in the same error.)What's the expected result?
I expect the
vite.build.target
setting to take effect duringnpm run dev
as well, so that the decorators are transformed and the above error does not occur.Link to Minimal Reproducible Example
https://stackblitz.com/github/koyopro/astro-debug/tree/build_target?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: