Closed maheshkrsna closed 5 years ago
Remove the && and retry
"start": "cross-env DEBUG=true webpack-dev-server";
Just tested on windows
//index.js
console.log(process.env.NODE_ENV);
"scripts": {
"dev": "cross-env NODE_ENV=dev node index.js",
"prod": "cross-env NODE_ENV=prod node index.js",
"error": "cross-env NODE_ENV=dev && node index.js"
}
dev prints "dev" prod prints "prod" error prints undefined
@bibo5088 Yes, removing the &&
worked. Thanks.
May I ask why I have to remove the && ? @bibo5088
&&
is used in shells to run multiple commands in sequence.
So cross-env DEBUG=true && webpack-dev-server
would be read as run command cross-env DEBUG=true
and after that run command webpack-dev-server
.
cross-env
would not receive webpack-dev-server
as an argument and wouldn't run it.
cross-env
doesn't modify the current instance's variables, rather it spawns a new shell and runs the command in it.
cross-env
version: ^5.2.1node
version: 10.15.1npm
version: 6.4.1Relevant code or config
package.json > "scripts"
webpack.config.js
What you did: add the above code snippets in a react project and run it as an npm script on windows OS.
What happened: React code runs with production version instead of debug version. Looks like
cross-env
isn't setting the debug variable. There are no errors thrown though.Reproduction repository:
Problem description:
cross-env
isn't setting custom process environment variables on windows OS.Suggested solution: