-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Optional Environment Variables #7364
Comments
Maybe you can define an empty process.env with DefinePlugin. https://rspack.dev/zh/plugins/webpack/define-plugin new rspack.DefinePlugin({
"process.env": {},
}), |
it's indeed a non documented breaking change in rspack beta 1.0.0 beta0, see web-infra-dev/rsbuild#3029 |
Currently Rspack/Webpack does not support |
Hmm rsbuild/rspack supports |
ok, we will find a better way to handle this |
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
bump |
It's worth noting that rspack is the outlier here: The following code will work across all runtimes and bundlers but breaks in rspack. expect(import.meta.env?.SOME_MISSING_VAR ?? 42).toBe(42); See " |
yeah it's a bug and we're gonna fix it |
I'm not quite sure if this fits here exactly but I can imagine that it is related to the same bug. I have also noticed the following which irritates me and where I expect different behavior. console.log(import.meta.env) // undefined
console.log(import.meta.env['PUBLIC_TEST']) // value
console.log(import.meta.env.PUBLIC_TEST]) // value
let x = 'PUBLIC_TEST';
console.log(import.meta.env[x]) // Cannot read properties of undefined (reading 'PUBLIC_TEST') Perhaps this can also be taken into account. |
I was wondering if there have been any updates on this issue? 🤞 |
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
System Info
System:
OS: macOS 14.5
CPU: (8) arm64 Apple M2
Memory: 88.97 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.14.0/bin/yarn
npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
pnpm: 9.5.0 - ~/.nvm/versions/node/v20.14.0/bin/pnpm
bun: 1.1.21 - ~/.bun/bin/bun
Browsers:
Chrome: 127.0.6533.73
Safari: 17.5
Details
When trying to access env vars via:
process.env.PUBLIC_NICE
import.meta.env.PUBLIC_NICE
And I don't have PUBLIC_NICE in my .env. It throws an error instead of just being undefined.
Afaik in Vite, I'm allowed to have optional env variables. I usually setup my config in a typescript file with default values for local like:
Reproduce link
No response
Reproduce Steps
Make an rspack project
Go to App.tsx and write process.env.PUBLIC_NICE somewhere
Run the app (expect: error)
Add PUBLIC_NICE="Hello" to .env
Run the app (expect: no errors)
The text was updated successfully, but these errors were encountered: