“NODE_ENV” is not recognized as an internal or external command, operable command or batch file

后端 未结 16 1497
清歌不尽
清歌不尽 2020-11-29 15:33

I\'m trying to setup an environment for a Node.js app. but I\'m getting this error every time.

\"NODE_ENV\" is not recognized as an internal or extern

相关标签:
16条回答
  • 2020-11-29 16:19

    I had the same problem and on windows platform and i just ran the below command

    npm install -g win-node-env
    

    and everything works normally

    0 讨论(0)
  • 2020-11-29 16:23

    for windows use & in between command also. Like,

      "scripts": {
        "start": "SET NODE_ENV=development & nodemon app/app.js",
      }
    
    0 讨论(0)
  • 2020-11-29 16:24

    Changing your scripts to accommodate Windows is a royal pain. Trying to figure out the appropriate Windows translations and maintaining 2 sets of scripts is no way to live your life.

    It's much easier to configure npm to use bash on Windows and your scripts will run as is.

    Simply run npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe". Make sure the path to the bash executable is correct for your machine. You'll likely need to start a new instance of the terminal for the change to take effect.

    The screenshot below illustrates the benefit.

    1. npm ERR! when trying to run script initially.
    2. Script modified for Windows use runs but doesn't show the return message.
    3. After updating npm config to use bash, the script runs and returns the appropriate message.

    0 讨论(0)
  • 2020-11-29 16:27
    1. npm install --save-dev "cross-env" module.
    2. modify the code as cross-env NODE_ENV=development node foo.js. Then you can run the like npm run build.
    0 讨论(0)
提交回复
热议问题