That's how I usually do that:
if-envnew NODE_ENV=productionwebpack.DefinePlugin({ && npm run start'process.env':prod ||{ npm run start NODE_ENV:dev JSON.stringify(process.env.NODE_ENV), }, }), This command startsAnd pass that to the array of the webpack plugins.
Why the problem happens: when wepack processes code npm run start:prod without- the code being processed is not actually run but simply read+processed. So when you run it NODE_ENV- then it's too late to access environment variables.
Since it's a separateYou're checking the environment for the process you mustrunning on server, while react runs in the browser so obviously it does not have access to passthe server process environment variables. Hence you need to inject it there explicitly, like during build time.
if-env NODE_ENV=production && NODE_ENV=production npm run start:prod || npm run start:dev