-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Describe the bug
When useDefineForClassFields is not set in tsconfig, the value is derived from target.
When target is ES2022+ or ESNext, useDefineForClassFields is true otherwise it's false.
This is documented here as well.
But it seems this was not working and still not working in some cases.
tsconfig.compilerOptions.target = 'ESNext' && build.target = 'ESNext'
| Vite | esbuild | command | resolved useDefineForClassFields |
|---|---|---|---|
| 3.0.9 | 0.14.47 | dev | false |
| 3.0.9 | 0.14.47 | build | false |
| 3.1.4 | 0.15.10 | dev | true |
| 3.1.4 | 0.15.10 | build | true |
The behavior changed but I think the new behavior is correct.
tsconfig.compilerOptions.target = 'ES2021' && build.target = 'ES2021'
| Vite | esbuild | command | resolved useDefineForClassFields |
|---|---|---|---|
| 3.0.9 | 0.14.47 | dev | false |
| 3.0.9 | 0.14.47 | build | false |
| 3.1.4 | 0.15.10 | dev | true |
| 3.1.4 | 0.15.10 | build | true |
The behavior changed and I think the new behavior is not correct.
tsconfig.compilerOptions.target = 'ESNext' && build.target = 'ES2021'
| Vite | esbuild | command | resolved useDefineForClassFields |
|---|---|---|---|
| 3.0.9 | 0.14.47 | dev | false |
| 3.0.9 | 0.14.47 | build | false |
| 3.1.4 | 0.15.10 | dev | true |
| 3.1.4 | 0.15.10 | build | true |
The behavior changed but I think the new behavior is correct.
tsconfig.compilerOptions.target = 'ES2021' && build.target = 'ESNext'
| Vite | esbuild | command | resolved useDefineForClassFields |
|---|---|---|---|
| 3.0.9 | 0.14.47 | dev | false |
| 3.0.9 | 0.14.47 | build | false |
| 3.1.4 | 0.15.10 | dev | true |
| 3.1.4 | 0.15.10 | build | true |
The behavior changed and I think the new behavior is not correct.
I think useDefineForClassFields should be derived from tsconfig.compilerOptions.target and not from build.target.
related esbuild's behavior
Before esbuild 0.15.8, esbuild derived useDefineForClassFields from build.target and not from tsconfig.compilerOptions.target. But from 0.15.8, it seems the behavior changed.
When target = 'es2021' + tsconfig.compilerOptions.target = 'esnext', I think the new behavior is correct.
When target = 'esnext' + tsconfig.compilerOptions.target = 'es2021', I think the behavior might not be correct.
esbuild repl 0.15.7 target = 'es2021' + tsconfig.compilerOptions.target = 'esnext'
esbuild repl 0.15.8 target = 'es2021' + tsconfig.compilerOptions.target = 'esnext'
esbuild repl 0.15.7 target = 'esnext' + tsconfig.compilerOptions.target = 'es2021'
esbuild repl 0.15.8 target = 'esnext' + tsconfig.compilerOptions.target = 'es2021'
Reproduction
https://stackblitz.com/edit/vitejs-vite-tkrvzm (Vite 3.0.9 && tsconfig.compilerOptions.target = 'ESNext' && build.target = 'ES2021')
System Info
System:
OS: Linux 5.0 undefined
CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
vite: ~3.0.0 => 3.0.9Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.