Closed chenyan-dfinity closed 2 months ago
I have another repo with vite's import.meta.env
. It's the same problem:
https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-hypsww?file=files.js
Hey @chenyan-dfinity! Thanks for the report!
I'm not sure about webpack but for vite, the environment variable is only exposed to the client if it starts with VITE_
.
Trying your vite example with a variable starting with VITE_
seems to work: https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-umcn6j
Thanks. I can confirm everything is working as expected. The problem was caused by something else in my code.
No problem! Thanks for double-checking and closing this issue :pray:
Describe the bug
I'm running
webpack 5
inside the web container, and passed in environment variableMYFLAG
. The source code usesprocess.env.MYFLAG
to read the environment variable. Inwebpack.config.js
, I can correctly read the MYFLAG value. But insrc/index.js
,process.env.MYFLAG
is sometimesundefined
, and sometimes the correct value. The result ofprocess.env.MYFLAG
in the bundled code is unpredictable. I tried to read pre-defined variables likeprocess.env.HOME
, the result is the same.Link to the blitz that caused the error
https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-fapmje?file=files.js
Steps to reproduce
webpack
, MYFLAG is correctly printed to console log.Expected behavior
webpack should read
process.env
reliably for bundled codeParity with Local
Screenshots
No response
Platform
No response
Additional context
No response