-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
vite will automatically escape and replace the string form"process.env.NODE_ENV:" content!!! #3077
Comments
Why not using e.g. |
yes! but I only want my string process.env.NODE_ENV don't be replaced ! |
While this section references To get what you want, just follow the docs there. I can't speak as to why static replacement is used, I can only assume that it is done for performance reasons. The drawback is that it has to be escaped in this way. |
@nrayburn-tech it is easy to use this workaround if people has the ownership of the code, but if the problem happens in third party package, it will depends on if that package owner would use this workaround or not. Now I am facing this issue now, I am using mobx@5.9.0, and when using vite, I got the following syntax error after process.env.NODE_ENV is replaced. So I think it would be better if there is a way to turn off the replacement at least before the third party fix the issue, otherwise before that I am blocked here. |
@ilovepumpkin this is an issue also with rollup (and maybe other bundlers). It is not going to be easy to fix this in Vite, and I don't think it will change in the near future. mobx for example decided to rework the way that |
@patak-js thank you! patch-package sounds a good trick. I will give it a try. |
I think we should close this issue, as it is the same behavior that rollup has. You can use
as suggested in #3077 (comment) |
Describe the bug
I want print process.env.NODE_ENV:
console.log("process.env.NODE_ENV:", process.env.NODE_ENV);
actually: bug :
1、browser Error: Uncaught SyntaxError: missing ) after argument list
2、browser/Sources : console.log(""development":", "development"); "process.env.NODE_ENV:" is replace development
expect :process.env.NODE_ENV: development
step:
1、npm init @vitejs/app
2、npm i && npm run dev
3、open and modify src\main.js
4、Refresh page http://localhost:3000/
The text was updated successfully, but these errors were encountered: