-
Notifications
You must be signed in to change notification settings - Fork 130
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
[Bug]: can't destructure process.env #3718
Comments
This is by design, see https://rsbuild.dev/guide/advanced/env-vars#identifiers-matching |
I see! I should have read better that part of the guide, which I was also taking a look at. Would be the case to make the thing is highlighted also in the Migrate guide from CRA to RsBuild? TY for the quick answer. |
The defined value is not allowed to be destructured in any build tool, this is the same in CRA (webpack) and Rsbuild (Rspack). 😄 So we do not need to highlight it in the migration guide. |
In CRA it works. I'm migrating precisely from a CRA standard setup (with webpack) where destructuring was used on process.env .... |
Thanks for the info, I just found out that CRA replaces |
Version
System:
OS: macOS 14.7
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 53.36 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Browsers:
Chrome: 129.0.6668.100
Safari: 18.0.1
npmPackages:
@rsbuild/core: ^1.0.1 => 1.0.2
@rsbuild/plugin-node-polyfill: ^1.0.1 => 1.0.4
@rsbuild/plugin-react: ^1.0.1 => 1.0.1
@rsbuild/plugin-sass: ^1.0.1 => 1.0.1
@rsbuild/plugin-svgr: ^1.0.1 => 1.0.1
Details
I am migrating a project from CreateReactApp to RsBuild.
The original project made massive use of the
REACT_APP_
injected env vars, and they were collected into a global const file structured as such:In migrating to RsBuild 1.0.1 I followed the migration guide, especially the step for environment variables .
However the above injection doesn't work anymore, as the resulting VAR1 and VAR2 are undefined. To make it work, I have remove the destructuring block and write as such:
Definitely not a blocker issue, but it took me a good 2 hours to understand what was going on.
Reproduce link
.
Reproduce Steps
npm run build
-> deploy app
-> runtime error in console
The text was updated successfully, but these errors were encountered: