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
import.meta.env causes build error if a stringified object is used in "define" #13496
Comments
Start a new pull request in StackBlitz Codeflow. |
I just spent the whole morning trying to figure out what was going on with a production build and arrived at this same conclusion. The build works fine under 4.3.3 but fails under 4.3.4. We are also using the same dependencies listed here (zustand and vite-plugin-sentry). The build works fine when run locally, but in GHA it shows the following error under 4.3.4:
|
Describe the bug
It seems that there is a mutually exclusive issue with
import.meta.env
at the moment.If there is a stringified object defined as a replacement value (e.g.
import.meta.env.VITE_FOO: JSON.stringify({ a: 'a', b: 'b' })
then the build will error when it encounters a bareimport.meta.env
.We have currently run in to this issue with two libraries we are using
vite-plugin-sentry
andzustand
, where one uses object values and one uses the bareimport.meta.env
.The documentation doesn't mention any restriction on which values can be used and it was suggested in a previous issue (#12857) that objects could be used. So I am assuming this is a bug in the current implementation.
This seems to only be a problem when building the project, during dev mode there are no problems.
My guess is that the bug was introduced in #13003 as there wasn't an issue before this change
Reproduction
https://stackblitz.com/edit/vitejs-vite-ttdkfj?file=main.js,vite.config.js&terminal=dev
Steps to reproduce
Run
npm run build
and the build will crash.Comment out either the object in the config or the bare env access in the main file and the build will succeed.
System Info
System: OS: Linux 5.0 undefined CPU: (2) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 16.14.2 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm npmPackages: vite: ^4.3.9 => 4.3.9
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: