vite: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
Describe the bug
Even with a minimal setup, vue-tsc fire errors when isolatedModules flag is active
Reproduction
https://github.com/francoislevesque/vite-issue
What I did
Very simple:
npm init vite@latest
# select vue + vue-ts
npm i
Set isolatedModules to true in tsconfig.json.
npm run build
Get the following errors:
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1193:6 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1193 [BooleanFlags.shouldCast]?: boolean;
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1194:6 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1194 [BooleanFlags.shouldCastTrue]?: boolean;
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1730:10 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1730 export { TrackOpTypes }
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1759:10 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1759 export { TriggerOpTypes }
~~~~~~~~~~~~~~
System Info
System:
OS: Windows 10 10.0.19042
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 4.64 GB / 15.74 GB
Binaries:
Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 96.0.4664.45
Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.29)
Internet Explorer: 11.0.19041.1202
npmPackages:
@vitejs/plugin-vue: ^1.9.3 => 1.10.0
vite: ^2.6.4 => 2.6.14
Used Package Manager
npm
Logs
> vite-issue@0.0.0 build
> vue-tsc --noEmit && vite build
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1193:6 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1193 [BooleanFlags.shouldCast]?: boolean;
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1194:6 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1194 [BooleanFlags.shouldCastTrue]?: boolean;
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1730:10 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1730 export { TrackOpTypes }
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1759:10 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
1759 export { TriggerOpTypes }
~~~~~~~~~~~~~~
Found 4 errors.
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 https://github.com/vuejs/vue-next 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.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 14
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Disabled isolatedModules & noImplicitAny flags. isolatedModules flag was causing vuejs reactivity compilation errors. See error below and https://github.com/vitejs/vite/issues/5814 & https://github.c... — committed to wrathofrathma/newtab by wrathofrathma 2 years ago
- Add skipLibCheck to tsconfig Default template can't build due to this error: "Cannot access ambient const enums when the '--isolatedModules' flag is provided." The errors are in node_modules/@vue/r... — committed to dave-burke/rpn-calc by dave-burke 2 years ago
- buildに失敗するため https://github.com/vitejs/vite/issues/5814 — committed to aocm/vue3-express-ssr-sample by aocm 2 years ago
- Vite 빌드 오류 수정 - ref https://github.com/vitejs/vite/issues/5814 — committed to blood72/vitejs-vue-practice by blood72 2 years ago
- Fix (hack) tsc compiler complaining about isolatedModules... https://github.com/vitejs/vite/issues/5814 https://github.com/vuejs/core/issues/1228 — committed to amcsi/live-scripts by amcsi 2 years ago
Okay so it looks like this is happening because
vue-tscis usingtscunder the hood and it will also check the types of all packages used in the node_modules directory. The vue project has been transpiled with different options than what the Vite docs specify/want. So add the"skipLibCheck": trueflag to your tsconfig.json, it will then ignore all other modules and only check the code you write (not in node modules).https://www.typescriptlang.org/tsconfig#skipLibCheck
Is it safe to turn it off? https://stackoverflow.com/questions/52311779/usage-of-the-typescript-compiler-argument-skiplibcheck The accepted answer:
I recently reread the vite docs to make sure I was up to date and updated my tsconfig accordingly (see https://vitejs.dev/guide/features.html#typescript-compiler-options) and am seeing this as well.
Just adding this note so in case docs need to be updated one way or another…
Sounds like a harmless change 👍 I’ve created #7785 to add a small note for it.
in
tsconfig.json, edit"isolatedModules": true,to"isolatedModules": false,Same problem here. I can currently work around it but when it comes to release I’d like to get it working.