Skip to content
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]: Disabling optimizations.nodeEnv does nothing #6214

Closed
Blitss opened this issue Apr 11, 2024 · 2 comments · Fixed by #6219
Closed

[Bug]: Disabling optimizations.nodeEnv does nothing #6214

Blitss opened this issue Apr 11, 2024 · 2 comments · Fixed by #6219
Assignees
Labels
bug Something isn't working

Comments

@Blitss
Copy link

Blitss commented Apr 11, 2024

System Info

System:
OS: macOS 14.3.1
CPU: (12) arm64 Apple M2 Pro
Memory: 79.41 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 4.1.1 - /opt/homebrew/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: 8.15.4 - ~/Library/pnpm/pnpm
bun: 1.1.3 - ~/.bun/bin/bun
Browsers:
Chrome: 123.0.6312.107
Safari: 17.3.1

Details

In webpack there's an option that you can use to disable nodeEnv optimization. Setting it to false doesn't seem to do anything in rspack (it is still replaced and optimization is on), although it is supposed to avoid replacing NODE_ENV variable. I didn't find any plausible way to avoid process.env.NODE_ENV from overwriting by the bundler.

 optimization: {
    nodeEnv: false,
  },

Reproduce link

No response

Reproduce Steps

  1. Create any starter project
  2. Set optimization.nodeEnv to false and use console.log(process.env.NODE_ENV) in the file
  3. Build project in production/development mode, doesn't matter
  4. NODE_ENV is overwritten in the output file
@Blitss Blitss added bug Something isn't working pending triage The issue/PR is currently untouched. labels Apr 11, 2024
@LingyuCoder
Copy link
Collaborator

LingyuCoder commented Apr 12, 2024

Caused by rspack-cli.

This is the compatible coded in the early days when the optimization.nodeEnv was not supported, and now it should be deleted. But because the deletion will cause a breaking change, we will remove it in 0.7.0.

@LingyuCoder LingyuCoder removed the pending triage The issue/PR is currently untouched. label Apr 12, 2024
@LingyuCoder LingyuCoder self-assigned this Apr 12, 2024
@Blitss
Copy link
Author

Blitss commented Apr 12, 2024

Caused by rspack-cli.

This is the compatible coded in the early days when the optimization.nodeEnv was not supported, and now it should be deleted. But because the deletion will cause a breaking change, we will remove it in 0.7.0.

Okay great, if you delete it would that mean that NODE_ENV wouldn't be replaced by default (and you'd need to use a DefinePlugin for that), or is there a different option in config that handles replacing NODE_ENV?

Only woke up at the moment, so if I'm getting this correctly this PR means that optimizations.nodeEnv would work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants