The scripts statements in package.json are as follows
"test": "cross-env NODE_ENV=dev && node test.js"
test.js has only one sentence console.log(process.env.NODE_ENV)
console.log(process.env.NODE_ENV)
But the result shows undefined
undefined
Why?
Ask and answer your own question, the reason is that there cannot be anything in the middle&&,&&This will divide the two environments before and after, resulting in the environment of the latter statement not having NODE_ENV
&&
NODE_ENV=dev这里不能有空格"test": "cross-env NODE_ENV=dev&& node test.js"
NODE_ENV=dev
"test": "cross-env NODE_ENV=dev&& node test.js"
Ask and answer your own question, the reason is that there cannot be anything in the middle
&&
,&&
This will divide the two environments before and after, resulting in the environment of the latter statement not having NODE_ENVNODE_ENV=dev
这里不能有空格"test": "cross-env NODE_ENV=dev&& node test.js"