Skip to content
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

npm run scripts on Windows #44

Open
pmosconi opened this issue Jan 1, 2019 · 6 comments
Open

npm run scripts on Windows #44

pmosconi opened this issue Jan 1, 2019 · 6 comments
Labels
bug Something isn't working Windows

Comments

@pmosconi
Copy link

pmosconi commented Jan 1, 2019

npm run scripting syntax is slightly different on Windows due to the underlying shell being used. Usually the default is cmd.exe (the old DOS), even though it is possible to override the default.

The key changes required for the testing scripts (p. 315 of the book) are:
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js"
In test-server, there is no space between the variable's value and && on purpose otherwise trailing spaces would be added to the value (https://stackoverflow.com/questions/25112510/how-to-set-environment-variables-from-within-package-json-node-js#comment58812038_27090755).
Note that TEST_DATABASE=mytestdatabase && npm start will not work in Linux because && starts another shell where the variable is not defined.

In test, single quote are omitted otherwise * are not expanded, or at leasr I think.

Unfortunately there is no way to define cross environment scripts without using external packages.

@rwieruch
Copy link
Member

rwieruch commented Jan 2, 2019

Thanks for reporting this @pmosconi Need to check how to fix this! Any help on it is very much appreciated if anyone else runs into this 👍

@pmosconi
Copy link
Author

pmosconi commented Jan 2, 2019

For simple scripts the best solution is using cross-env:
"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"
I'm not sure about quote expansion though.

@tmstani23
Copy link

tmstani23 commented Jan 15, 2019

Pmosconi's solution worked for me on Windows. I think the book should be updated to note this for Windows users as I spent about 2 hours trying to figure out what was going on before coming here. I am guessing there are many readers who have been stuck at this part of the book.

@rwieruch
Copy link
Member

Thank you for confirming @tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", 
"test": "mocha --require @babel/register src/**/*.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

@rwieruch rwieruch added bug Something isn't working Windows labels Jan 16, 2019
@tmstani23
Copy link

tmstani23 commented Jan 16, 2019 via email

@pmosconi
Copy link
Author

pmosconi commented Jan 16, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

No branches or pull requests

3 participants