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

--define-process-env-node-env doesn't do as advertised #3503

Closed
CreativeTechGuy opened this issue Nov 27, 2022 · 8 comments · Fixed by #3514
Closed

--define-process-env-node-env doesn't do as advertised #3503

CreativeTechGuy opened this issue Nov 27, 2022 · 8 comments · Fixed by #3514
Labels

Comments

@CreativeTechGuy
Copy link
Contributor

Describe the bug

This is a follow up from this comment thread. --node-env was renamed in webpack-cli v5 with this comment linked as the reasoning.

I wanted to rename node-env, because it is confising, many developers using node-env think that it will change process.env.NODE_ENV inside webpack.config.js, but it only change process.env.NODE_ENV in code, that is why I think we need another name for this.

This is not true, not in the previous version and not in the new version. See "To Reproduce" section below for a very minimal demo proving this isn't true.

What is the current behavior?

process.env.NODE_ENV is set to the value of --node-env/--define-process-env-node-env within both webpack.config.js and the rest of the application.

To Reproduce

These are the only two files needed to reproduce. Install the dependencies and run either command and see the value logged.

Gist: https://gist.github.com/CreativeTechGuy/ae6ec05ee9ec5cb71807f2ff74a99c41

Expected behavior

There's a conflict. --define-process-env-node-env is named as such to (attempt to) make it clear that it doesn't set the environment variable within webpack.config.js. That precondition doesn't seem to be true. So the previous name --node-env is much simpler and easier to understand and does do what you'd expect it to do.

@alexander-akait
Copy link
Member

alexander-akait commented Nov 27, 2022

Why don't use NODE_ENV=production?

This is not true, not in the previous version and not in the new version. See "To Reproduce" section below for a very minimal demo proving this isn't true.

We don't change NODE_ENV in webpack.config.js when you use --node-env

@alexander-akait
Copy link
Member

Oh, our mistake https://github.com/webpack/webpack-cli/blob/master/packages/webpack-cli/src/webpack-cli.ts#L2179

@snitin315 I think we need to decide better strategy here, make sense to have ability set NODE_ENV in runtime code and set NODE_ENV in webpack.config.js to avoid using cross-env

@CreativeTechGuy
Copy link
Contributor Author

The current (and previous) behavior (of setting NODE_ENV in both runtime and config) seems to make sense. It's really easy to reason about and and does what you'd expect. The name --node-env previously described this behavior pretty succinctly. I wish we could have kept that.

@alexander-akait
Copy link
Member

@snitin315 I think yes, it was my mistake (I forgot about we set NODE_ENV), so let's return --node-env, but keep --define-process-env-node-env (without setting NODE_ENV, it can be useful for stagging or another modes)

@snitin315
Copy link
Member

I'll raise a PR.

@CreativeTechGuy
Copy link
Contributor Author

Thank you all! Much appreciate your work. 😃

@CreativeTechGuy
Copy link
Contributor Author

@snitin315, would I be able to help out in any way? Maybe submitting a PR to get started with or something?

@snitin315
Copy link
Member

@CreativeTechGuy yes, feel free to send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants