-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
"process.env.NODE_ENV" causes invalid code injection #9829
Comments
Interestingly, when running unit tests that trigger this bug (e.g., |
Good point. If we merge #9791, it does mean that this bug wouldn't happen as well, but I don't see another way around this, except doing the replacement in |
I don't think the other PR would prevent this bug from occurring. This plugin still does a string replacement regardless of what the Oh, I think you mean that the |
|
Just ran into this problem too. My workaround/hack was to substitute using single-quotes instead of JSON stringified double-quotes as to not break mistakenly identified occurances (inside double-quoted string literals) and also work as a valid string literal on its own (for intended replacements). // vite.config.ts
{
define: {
"process.env.NODE_ENV": `'${process.env.NODE_ENV}'`
}
} |
Describe the bug
Vite's
client-inject
plugin indiscriminately replacesprocess.env.NODE_ENV
, even in comments and string literals. This is similar to #9790, where the issue happens in Vite'sdefine
plugin.This becomes a problem in the following Vue template:
@vue/compiler-sfc
transforms that into this:...which is passed to the
client-inject
plugin , which transforms that into this invalid JavaScript:...which results in this runtime error:
Also see #3304 (comment)
Reproduction
https://stackblitz.com/edit/vitejs-vite-yw5t84?file=src%2Fcomponents%2FHelloWorld.vue
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: