简体   繁体   中英

process.env.NODE_ENV is undefined in one project, but not another

I am using the react boilerplate framework to develop two projects. Both projects use cross-env to inject a value into the process.env.NODE_ENV. my webpack package.json is identical in both projects, and an excerpt is:

"scripts":{
...
 "build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout",    
 "start": "cross-env NODE_ENV=development node server",
...  
}

the issue i have is that the process.env.NODE_ENV is set one project and works as expected, but not the other.

I have run diffs over much of the code in the two projects and the contents are the same, especially for the code that is from the react boilerplate.

Aside from not setting the process.env.NODE_ENV, the rest of the app works fine.

I have tried removing the node_modules folder and package-lock.json and done an npm install

So my question is, how can I work out why the process.env.NODE_ENV is undefined, and how can it be set?

for some reason,

import process from 'process';

had crept into the imports section of my files in the second project. Sharing this answer in case this happens for someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM