36

I installed npm-run-all and also configured the environment variable (which may or may not be not required) on my Windows machine but am getting an error:

'npm-run-all' is not recognized as an internal or external command, operable program or batch file

I am trying to build my current project with npm run build which includes the script where the error is thrown:

npm-run-all -p build-css build-webpack

Do I have to do any additional things to make it run?

Matt Holland
  • 2,190
  • 3
  • 22
  • 26
topreddy
  • 569
  • 1
  • 6
  • 7

9 Answers9

49
  1. Make sure the npm-run-all is in your package.json devDependencies.
  2. If npm-run-all is present in your package.json, run npm i
  3. If not present install it, run: npm i npm-run-all -D

If error is still present, follow these steps:

  1. Remove node_modules folder: run rm -rf node_modules
  2. Install all dependecies: run npm i

Hope this helps!

Jojo Tutor
  • 810
  • 6
  • 7
  • 1
    Before removing the whole`node_modules` folder, you can try to only remove `node_modules/npm-run-all` and then `npm install` - this helped for me: i.e. `run-s` was recreated in `node_modules/.bin`. – TmTron Sep 22 '21 at 14:14
20

You may just need to run the following command first (from the directory with the package.json file)

npm install
David
  • 3,488
  • 2
  • 21
  • 21
8

Please do that like this.

npm i npm-run-all -g

And then this issue will be fixed.

goldvenus
  • 898
  • 1
  • 10
  • 21
7

You have a couple of options here, besides installing npm-run-all as a global package as suggested by @Vaibhav in the comments:

1) Create an NPM script

The package.json file has a scripts section which can used to define shortcuts for anything you need to run while you're working on your app. There are some pre-defined scripts, like run or test than can be executed with simply npm start/npm test or you can define anything you like and then run it with npm run my-script-name. You could try:

{
  "scripts": {
    "start": "npm-run-all -p build-css build-webpack"
  }
}

Any NPM module referenced here "just works" (i.e. the path to the executable is resolved under the hood by NPM)

2) NPX

In newer versions of NPM (i.e. >= 5.2 or so), the "NPX" executable is provided. This has a similar effect to running commands inside an NPM script. You would run:

npx npm-run-all -p build-css build-webpack

Again, the path would be automatically resolved.

If you have an older NPM install, you can also install it separately:

npm install -g npx
Matt Holland
  • 2,190
  • 3
  • 22
  • 26
  • Hello Matt, thanks for the answer. installing npm-run-all globally worked. Do you know how to modify this script to run on windows cmd "build-webpack": "npm run clean && tsc && \"./node_modules/.bin/webpack\" && copy -R src/assets lib && node postbuild.js" – topreddy Feb 05 '19 at 18:11
  • @jaireddy you should be able to just refer to webpack as "webpack" inside an NPM script. As I said, the path gets resolved automatically, and that should work whatever the OS. Alternatively, there is a package called "cross-env" (https://www.npmjs.com/package/cross-env) that might be useful to you. – Matt Holland Feb 05 '19 at 18:25
2

npm install -g npm-run-all

Works for me.

Double check if npm-run-all is in your package.json devDependencies.

juagicre
  • 1,065
  • 30
  • 42
Ravi Kumar
  • 61
  • 4
0

I had same problem while using code editor Brackets.

To resolve the error, I did the following steps.

Add nodejs new system variable to your PC under Control Panel -> System -> Advanced System Settings

;C:\Program Files\nodejs\

After that, re-run command:

npm
Salomon Zhang
  • 1,553
  • 3
  • 23
  • 41
0

I don't know if this would help anyone, but I got this error because I was doing nodemon server.js instead of nodemon server/server.js. I wasn't in the right folder!

kp1
  • 1
  • 2
0

Did you reopen the terminal after you installed node?

If you have installed npm with the current terminal window open. Your terminal window will not have loaded the latest path settings (with npm location) to find the npm application to run the command. In this case try below steps .

  1. Try closing the current terminal session.
  2. Reopen a new session.
  3. Try the command again ( will pick up the new path settings with npm installed)
Ram
  • 15,908
  • 4
  • 48
  • 41
0

This worked for me.

npm audit fix --force

Also you can try downgrading your autoprefixer, seems version 10.0.0 doesn't work well with postcss

npm i autoprefixer@9.8.6
Damian
  • 1