How to use node's NODE_EN - Stack Overflow
代言
代言 2017-07-05 11:05:37
0
2
1068

Question 1: There is NODE_ENV=development in the project json.package file. Does it mean that executing npm run dev will set the node environment and switch to the development environment?

Question 2: So what is the difference between writing NODE_ENV=development and not writing it

  "scripts": {
    "compile": "NODE_ENV=production webpack",
    "start": "npm run dev",
    "dev": "NODE_ENV=development node --harmony bin/webpack-dev-server",
  },

Question 3: When I execute npm start, why does it fail to run normally?

$ npm start

> react-redux-jwt-auth-example@0.1.0 start C:\Users\Administrator\Desktop\react-redux-jwt-auth-example
> npm run dev


> react-redux-jwt-auth-example@0.1.0 dev C:\Users\Administrator\Desktop\react-redux-jwt-auth-example
> NODE_ENV=development node --harmony bin/webpack-dev-server

'NODE_ENV' ▒▒▒▒▒ڲ▒▒▒▒ⲿ▒▒▒Ҳ▒▒▒ǿ▒▒▒▒еij▒▒▒
▒▒▒▒▒▒▒▒▒ļ▒▒▒

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\Program Files\nodejs\node.exe" "D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! react-redux-jwt-auth-example@0.1.0 dev: `NODE_ENV=development node --harmony bin/webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-redux-jwt-auth-example@0.1.0 dev script 'NODE_ENV=development node --harmony bin/webpack-dev-server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the react-redux-jwt-auth-example package,
npm ERR! not with npm itself.
代言
代言

reply all(2)
Peter_Zhu
  1. npm run dev is a [conventional] development environment statement. The general habit is to set the NODE_ENV environment variable in this statement. It’s not necessary, but everyone does it…

  2. If you don’t write it, then the development environment you started does not have the NODE_ENV variable set. This environment variable is checked internally in Vue and React. For example, in React, when NODE_ENV is development, type checking is additionally turned on to facilitate development. This environment variable in Vue will also affect functions such as time travel inside plug-ins such as Vuex.

  3. There are pitfalls in environment variables under Windows. You may need the cross-env package to assist in setting environment variables.

淡淡烟草味

Write NODE_ENV=development and you can use the following code in the program to determine which environment you are in:

if (process.env.NODE_ENV === 'development') {
    // 开发环境
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template