node.jsnext.jsenvironment-variablesnext.js13nodeenv

You are using a non-standard "NODE_ENV" value in your environment - How to set the default value of NODE_ENV in windows


I changed the value of NODE_ENV to production using the command:

setx NODE_ENV production

Now in my nextjs project, anytime I run npm run dev or build, I get the error: You are using a non-standard "NODE_ENV" value in you environment.

node_env error in nextjs project

After doing some research, I found out this property is automatically provided by Nextjs and the default value is NEXT_PUBLIC_APP_ENV (I may be wrong about this).

I've tried to change the value back to the default: using setx NODE_ENV NEXT_PUBLIC_APP_ENV which works. Here's the result of running node followed by process.env in my terminal to confirm the change.

enter image description here

The problem is I still get the error every time I run npm run build or dev and in any nextjs project on my PC. I'm I missing something or is there another place this property is being added? Please help.


Solution

  • Turns out it was stored in my computer's environment variable. If you're on windows 7/10/11, here's the solution to fix this.

    Hold down Win + R to open the run box and enter sysdm.cpl to open your system properties.

    Next, navigate to the advanced tab and click Environment variables at the bottom.

    enter image description here

    You should see a list of all the env variables stored on your PC. Among the list should be the variable for NODE_ENV. Simply delete it and click okay to set it to default.

    Note: You may need to restart your terminal to see the changes.

    enter image description here