“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:04

    Do this it will definitely work

    "scripts": {
        "start": "SET NODE_ENV=production && node server"
    }
    
    0 讨论(0)
  • 2020-11-29 16:04

    For windows open git bash and try

    NODE_ENV=production node app.js

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

    process.env.NODE_ENV is adding a white space do this

    process.env.NODE_ENV.trim() == 'production'
    
    0 讨论(0)
  • 2020-11-29 16:13

    For those who uses Git Bash and having issues with npm run <script>,

    Just set npm to use Git Bash to run scripts

    npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" (change the path according to your installation)

    And then npm will run scripts with Git Bash, so such usages like NODE_ENV= will work properly.

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

    Use win-node-env, For using it just run below command on your cmd or power shell or git bash:

    npm install -g win-node-env
    

    After it everything is like Linux.

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

    If anyone else came here like me trying to find a solution for the error:

    'env' is not recognized as an internal or external command
    

    The reason I got this is that I was migrating an angular solution from a mac development machine over to a windows 10 desktop. This is how I resolved it.

    1. run npm install --save-dev cross-env

    2. go into my package.json file and change all the script references from env <whatever> to cross-env <whatever>

    Then my commands like: npm run start:some_random_environment_var now run fine on Windows 10.

    0 讨论(0)
提交回复
热议问题