Skip to content
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

Vue Component Type Build Error with __VUE_PROD_DEVTOOLS__ in Vite #13035

Closed
Coreight98 opened this issue Mar 14, 2025 · 3 comments
Closed

Vue Component Type Build Error with __VUE_PROD_DEVTOOLS__ in Vite #13035

Coreight98 opened this issue Mar 14, 2025 · 3 comments

Comments

@Coreight98
Copy link

Coreight98 commented Mar 14, 2025

Vue version

3.4.3

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-guabna1b?file=vite.config.ts&file=src%2Fcomponents%2FDynamicComponent.vue&terminal=dev

Steps to reproduce

  • In tsconfig.json, set the verbatimModuleSyntax option to false, and use the Component type without explicitly specifying type in the import statement.
  • In vite.config.ts, declare the __VUE_PROD_DEVTOOLS__ flag as 'false'.

What is expected?

The build should work correctly regardless of whether the import type statement is used.

What is actually happening?

Image

In the vite.config.ts file, when the __VUE_PROD_DEVTOOLS__ flag is declared, a build error occurs if you use Vue's Component type without explicitly specifying the type in the import statement.

System Info

Any additional comments?

No response

@yangxiuxiu1115
Copy link
Contributor

vue only exports the Component's type definition, there is no associated class or method implementation, if you set verbatimModuleSyntax: false, it does cause the problem you mentioned. I think this might be as expected though?

I haven't found a role for VUE_PROD_DEVTOOLS in this, it seems to fail to package/render whether the VUE_PROD_DEVTOOLS value is set or not

@Coreight98
Copy link
Author

Coreight98 commented Mar 14, 2025

vue only exports the Component's type definition, there is no associated class or method implementation, if you set verbatimModuleSyntax: false, it does cause the problem you mentioned. I think this might be as expected though?

I haven't found a role for VUE_PROD_DEVTOOLS in this, it seems to fail to package/render whether the VUE_PROD_DEVTOOLS value is set or not

Since our company project is private, I created a new project on StackBlitz to help explain the issue!
When I reproduced the problem locally, rendering worked correctly, but on StackBlitz, an error occurred during rendering.
(After trying again in a new project, it turns out that the issue indeed occurs during rendering!
In that case, it seems more like a problem with @vitejs/plugin-vue related to the VUE_PROD_DEVTOOLS flag, rather than an error in Vue itself.)

In the local environment, the build works fine if the VUE_PROD_DEVTOOLS flag is not defined, but if the flag is defined, an error occurs.

What’s strange is that the default value of VUE_PROD_DEVTOOLS is false, yet defining it as the same 'false' causes an error.

So, I thought it might be related to VUE_PROD_DEVTOOLS, which is why I decided to raise an issue.

@jh-leong jh-leong added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Mar 14, 2025
@jh-leong
Copy link
Member

Thanks for the report.

The issue is caused by vite-plugin-vue incorrectly parsing __VUE_PROD_DEVTOOLS__: 'false' as true. I'm working on a fix here: vitejs/vite-plugin-vue#545.

Additionally, the root cause in this case relates to the non-inline mode compiler: minimal reproduction.

@jh-leong jh-leong added scope: sfc 🔩 p2-edge-case and removed 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants