Skip to content

React process.env.NODE_ENV #2035

Answered by xc2
maxim-semikov asked this question in Q&A
Apr 8, 2024 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

please use process.env.NODE_ENV === 'development' instead of process?.env?.NODE_ENV === 'development'.

This is a common misconception about the "webpack definePlugin".

nowadays the term "define" in js building field typically means replacing expression instead of declare a variable.

e.g.

define: {"process.env.NODE_ENV": '"production"'} will transform process.env.NODE_ENV === 'development' into "production" === 'development' but not const process = {env: {NODE_ENV: "production"}}; process.env.NODE_ENV === 'development';

process?.env?.NODE_ENV doesn't match the expression process.env.NODE_ENV so it is not replaced.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@xc2
Comment options

xc2 Apr 8, 2024
Collaborator

Answer selected by maxim-semikov
@maxim-semikov
Comment options

@hussain-nz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants