-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
(reactivity) Type check fails when '--isolatedModules' flag is provided #1228
Comments
You can remove |
The same error was found after changing typescript to v3.8.3. |
I'm Sorry for typed error with |
Surely This error is happening because const enums are emitted in the definition files provided by Vue. That doesn't make sense to me - surely const enums are not valid in definition files? They have no runtime equivalent so can't be ambient in any context, I'd consider this a bug, not an enhancement. It would be a blocker for me using Vue 3 in production because I can't consider deploying without type checking. |
FYI setting |
@sapphi-red thanks, that does work. However, either this is now a docs bug (should mention |
For completeness, it's worth pointing out that |
Experiencing this in my project too. In my use-case, I'm trying to reference the Curious what the expected solution would be on Vue's end to provide a run-time solution? I found a similar problem in chalk, and the fix was to convert the enum to a union... but seems only sufficient for build-time type-checking. Edit: |
Unfortunately, this is still an issue. The output from my recent conversion from vue-cli to vite:
Using vue 3.1.1 and vite 2.3.7 - this is going to block me from using vite. The site is migrating from vue-cli to vite, so I can still build/deploy, but I was really hoping for the full vite experience. |
As a less-than-ideal workaround, I just copied the file from ...
"paths": {
"@vue/runtime-core": [
"src/types/runtime-core.d.ts"
]
},
... Because in vite, all I am using Downside is that, until this is properly resolved, I will need to keep this file up to date manually. However, in my particular case, I think the gains in dev experience might be worth the occasional need to diff this file...for now...especially since there are literally only 4 lines in question. |
Any word on a fix for this? Using vite 2.7.10, vue 3.2.6, and this still comes up if I don't manually override. Offending lines in the generated typescript defs are now 1215-1216, 1405, 1758 and 1787. Those are the following: // 1215-1216: The "declare type" line itself is fine, the issue is just the references to BooleanFlags
declare type NormalizedProp = null | (PropOptions & {
[BooleanFlags.shouldCast]?: boolean;
[BooleanFlags.shouldCastTrue]?: boolean;
});
// 1415: The export is a const enum
export { ReactiveFlags }
// 1758: The export is a const enum
export { TrackOpTypes }
// 1787: The export is a const enum
export { TriggerOpTypes } |
isolatedModules flag was causing vuejs reactivity compilation errors. See error below and vitejs/vite#5814 & vuejs/core#1228 ``` node_modules/@vue/reactivity/dist/reactivity.d.ts:26:15 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided. 26 readonly [ReactiveFlags.IS_READONLY]: boolean; ``` noImplicitAny flag was causing compilation errors when using named slots.
I'm also getting this issue on a fresh Vite app. What am I expected to do? |
Also encountering that rn while running only way to temporally fix it is to disabled NB: that's ofc not an ideal solution |
well setting isolatedModules to false works for me. |
Vite uses esbuild, which is why they recommend
|
I think it's pretty clear from the original bug description, and numerous comments following, that the masses wish to follow the official recommendation to use My prior comments started out by indicating devs could comment out the offending lines in a copy of the type definitions (since the offending lines are often vue internals anyway) - I have since started using patch-package to accomplish this in a much cleaner, maintainable way. It's not ideal to keep around a patch for type definitions that really should be fixed, but it's better than making a copy that quickly gets out of date, and enables me to keep the safety net that typescript provides. Please fix the type definitions so devs can follow the vite docs! |
Just chiming in here, please fix this! Especially since this is now default for vite's vue-ts template: vitejs/vite#7304 |
Also wondering what the status of this is? |
I'd like to chime in here that as a fairly new user to TypeScript, this |
Wow, this is a really serious Vue bug that prevents adoption into a modern JS workflow that uses SWC or ESBuild (or a tool that uses those, like Next.js or Vite). |
These enums also result in an issue with the
Vue version 3.3.4 |
Just share my problem here. I'm trying to migrate Vue Mini to Vitest from Jest, just like Vue did. But const enum blocked me, because esbuild can't resolve const enum from @vue/reactivity. I opened a feature request in esbuild: evanw/esbuild#3359, if esbuild do provide this feature, my problem will be solved. If Vue find a way to remove const enum, my problem will also be solved. |
closed via #9261 |
Great, thanks Evan |
Version
3.0.0-beta.14
Reproduction link
https://github.com/sapphi-red/vite-reactivity-isolated-modules-minimal-reproduction
Steps to reproduce
$ npm i
$ npm run check
What is expected?
no error with
Cannot access ambient const enums when the '--isolatedModules' flag is provided.
What is actually happening?
error was found as below
https://github.com/vitejs/vite#typescript
I turned on
isolatedModules
because vite recommends it.The text was updated successfully, but these errors were encountered: