Skip to content
Advertisement

Can’t set NODE_ENV=production with npm and webpack

I’m trying to access process.env.NODE_ENV inside my app, but I only get process is not defined when I check it.

package.json:

JavaScript

webpack.config.js:

const NODE_ENV = process.env.NODE_ENV ? process.env.NODE_ENV.toLowerCase() : 'development';

and below :

JavaScript

In the app source:

JavaScript

And it seems that process is not defined… What am I doing wrong here?

Advertisement

Answer

I’m not totally sure if the problem came from my scripts key inside package.json but it seems the NODE_ENV is now correctly set if I use this :

JavaScript

So I actually used cross-env and… it magically works. If you’re out of options like I was, you can still give this a shot.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement