question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm run scripts on Windows

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tmstani23commented, 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.

1reaction
pmosconicommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set shell for npm run-scripts in Windows - Stack Overflow
You can revert it by running: · 1. Wish this worked. · 4. This do the same job: $ npm config set shell...
Read more >
npm-run-script
Description. This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts.
Read more >
How to set GitBash as the default NPM script runner on Windows
Internally NPM runs your scripts on the default command terminal, independently from where you are triggering the scripts. This fact could confuse you...
Read more >
How to use NPM scripts for your development tasks ...
Automate your tasks with NPM scripts to make your workflow more efficient.Full "Intro to Node.js" course on Microsoft Learn: ...
Read more >
npm run-script doesn't work on windows when the ... - GitHub
Keep your command lines simple. A bash script won't work on Windows, for obvious reasons. Write a node program, or better yet, just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found