Closed khaosdoctor closed 6 days ago
Try changing target
of esbuild:
import { defineConfig } from "vitest/config";
export default defineConfig({
esbuild: {
target: "es2022",
},
test: {
// ...
},
});
This is not part of Javascript syntax and ESBuild will just parse it and pass through. If the target
is something else than esnext
, it will be transformed: https://github.com/evanw/esbuild/blob/main/CHANGELOG-2023.md#0185
This syntax is not yet a part of JavaScript but it was added to TypeScript in version 4.9. More information about this feature can be found in https://github.com/microsoft/TypeScript/pull/49705. Auto-accessors will be transformed if the target is set to something other than esnext
When esbuild doesn't transform this non-JS syntax, Rollup will fail to parse the file.
@AriPerkkio should we automatically lower esbuild
target to the lowest Node.js we support?
Yep, that worked fine @AriPerkkio thanks!
should we automatically lower
esbuild
target to the lowest Node.js we support?
I'm not sure. As esbuild
is only used for TS files, it would create a weird situation where different syntax would not work on JS file.
Describe the bug
If you create a simple TypeScript file with a class like so:
And try to write a test importing this file, rolloup throws an error
Unexpected token
bar. Expected * for generator, private key, identifier or async
Reproduction
I'm testing with the following file: https://github.com/Formacao-Typescript/projeto-3/blob/vitest/src/domain/Class.ts And this is the test: https://github.com/Formacao-Typescript/projeto-3/blob/vitest/src/domain/Class.test.ts
If I keep the accessor keyword:![image](https://github.com/vitest-dev/vitest/assets/3200560/2fdb749d-5eec-47bf-a231-28bcfd017f7e)
If I remove the keyword:![image](https://github.com/vitest-dev/vitest/assets/3200560/43a0021d-0391-4efe-8f64-d6d2de6c3ec1)
System Info
Used Package Manager
npm
Validations