Search code examples
environment-variablescreate-react-app

Can you override the NODE_ENV env variable in create-react-app@3.x?


I'd like to manually change the value of the NODE_ENV environment variable when I build my React app in development node (yarn run start).


Solution

  • No, as per create-react-app@3.4.1 at least, this is not possible. Excerpt from the docs:

    There is also a built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to 'development', when you run npm test it is always equal to 'test', and when you run npm run build to make a production bundle, it is always equal to 'production'. You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production.