Under Setting ENV, command is different for PowerShell
Closed this issue · 6 comments
When going through your article, I was using Visual Studio Code for windows. In that app, it shells out to PowerShell within the application. In order to get the environment setting to work properly, I had to run this:
$env:NODE_ENV="production"; ./node_modules/.bin/rollup -c
When I tired to use your command as outlined below within a regular command window, it did not work, it only set the NODE_ENV variable to be actually "production ./node_modules/.bin/rollup".
NOTE: On Windows, use SET NODE_ENV=production ./node_modules/.bin/rollup -c to avoid an error setting environment variables.
I found this solution via StackOverflow at this location: http://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-in-windows
@russdawginteractive Could you do me a favor and try this?
SET NODE_ENV="production" ./node_modules/.bin/rollup -c
I'm wondering if it's a lack of quotes that caused that issue.
@jlengstorf It's strange. That does not work in either Powershell or a regular command window. I created a quick link to show you what I'm seeing when I run the command you suggest.
@russdawginteractive I don't have Flash, and it appears screencast.com requires that plugin, so I can't see the video.
However, I've added a note to the article referencing this issue for anyone on Windows who hits the same snag. Thanks for sharing!
As a follow up, I came across this same issue on another project. Upon doing some further research, I found that using the command below works in Powershell:
set NODE_ENV=production&&./node_modules/.bin/rollup -c
Alternatively, there is a plugin called cross-env that will work across systems:
https://www.npmjs.com/package/cross-env
One important thing to note is that there should be no space between NODE_ENV=production
and &&
. But you can have spaces after &&
as shown below.
"scripts": {
"build": "rollup -c",
"buildprod": "SET NODE_ENV=production&& rollup -c"
},
If you have a space before &&
, windows adds the space to NODE_ENV
.
So the value will be set to production
<- notice the space.
therefore it won't work.
I think an easier solution to this would be to use https://www.npmjs.com/package/cross-env
If someone wants to submit a PR, I'd be much obliged.