Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`npm build` doesn't run the script named "build" in package.json

People also ask

How do I run a npm script in package json?

To define an NPM script, set its name and write the script under the 'scripts' property of your package. json file: To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably.

How do I fix a missing script build?

To solve the Missing script: "build" error, make sure to add a build command to the scripts object in your package. json file and open your shell or IDE in the root directory of your project before running the npm run build command.


Unfortunately npm build is already an internal command, as described in the docs:

This is the plumbing command called by npm link and npm install. It should generally not be called directly.

Because that command already exists, it always shadows over your "build": "node build.js".

The fully-qualified way to run your own script is with run-script or its alias run:

$ npm run build

npm start and others are the short-hand way, but is only an option when an existing npm command doesn't shadow it, like npm build does.


For posterity (as others have mentioned) npm build is used by npm to build native C/C++ Node addons using node-gyp.


The script named as "build" in package.json is not special in any way. The only way to get it to run is to call:

npm run-script build

There are some names which are called automatically by npm, but "build" is not one of them. The full list is:

  • prepublish, publish, postpublish
  • preinstall, install, postinstall
  • preuninstall, uninstall, postuninstall
  • preversion, version, postversion
  • pretest, test, posttest
  • prestop, stop, poststop
  • prestart, start, poststart
  • prerestart, restart, postrestart
  • preCUSTOM and postCUSTOM for custom script names.

OK, to run a build on it's own, use:

npm run-script build

Npm build expects

A folder containing a package.json file in its root

Try using npm scripts in your package.json, like the classic npm start


I had a problem with npm run build not printing anything. ended up using npm run build --verbose to get the output I needed.