New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Under Setting ENV, command is different for PowerShell #30

Closed
russdawginteractive opened this Issue Apr 3, 2017 · 6 comments

Comments

3 participants
@russdawginteractive

russdawginteractive commented Apr 3, 2017

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

@jlengstorf

This comment has been minimized.

Owner

jlengstorf commented Apr 11, 2017

@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.

@russdawginteractive

This comment has been minimized.

russdawginteractive commented Apr 11, 2017

@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.

https://www.screencast.com/t/cBHdHmE0cmHm

@jlengstorf

This comment has been minimized.

Owner

jlengstorf commented Apr 29, 2017

@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!

@russdawginteractive

This comment has been minimized.

russdawginteractive commented May 4, 2017

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

@dance2die

This comment has been minimized.

dance2die commented Apr 11, 2018

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.

@jlengstorf

This comment has been minimized.

Owner

jlengstorf commented Apr 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment