32

When I run npm build, it gives this error:

npm WARN build `npm build` called with no arguments

So, what's the difference between npm run-script build and npm build?

ruakh
  • 166,710
  • 24
  • 259
  • 294
Elangovan
  • 3,349
  • 4
  • 29
  • 37
  • The [documentation](https://docs.npmjs.com/cli/run-script) says: *This is the plumbing command called by npm link and npm install. It should generally be called during installation, but if you need to run it directly, run: `npm run-script build`* – Datz Aug 06 '19 at 15:12

2 Answers2

16

npm run-script is a way to execute arbitrary commands specific to the project/package. Check your applicable package.json file, which will have defined what happens when you execute npm run-script build for that package. It may also include what happens when you run common commands, such as npm run-script test.

As you can see in the documentation for npm run-script, this arbitrary command can include arguments, which you need to refer to your package.json to learn more about.

npm build is not a unique command to the package, and is a native command that ships with npm, as you can see in its documentation.

  • 12
    I suspect that this answer was never accepted because it is just as confusing to *NPM Noobies* as the documentation. I came here because I did not understand when to use `npm run-script` and when to use `npm build` in the documentation. This answer gets me no closer to understanding. – jp2code Nov 12 '20 at 22:08
9

The best answer is in this SO article.

Basically...

npm run == npm run-script

Plus, certain common tasks are aliased so that the following are true...

npm test == npm run-script test

npm build == npm run-script build

For common tasks, use...

npm start

npm build

npm test

npm restart

And for all others, use...

npm run <my-task>

Jimmy
  • 2,705
  • 6
  • 40
  • 57
Jeremy Foster
  • 4,553
  • 2
  • 27
  • 46