npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Failure to run `prepublishOnly` should always throw an error rather than just a warning

What I Wanted to Do

Configure a build script to run before publishing, by calling it in prepublishOnly script.

What Happened Instead

When running npm publish, due to a permission error the prepublishOnly failed with the following error:

prepublishOnly: cannot run in wd @xxxxxt@xxxx npm run build (wd=xxxxxxx)

But instead of stopping there the publication continued and ended up publish a broken package as the built assets where not generated.

This problem happens only in the case of the cannot run in wd error. If the prepublishOnly scripts runs and fails, the error does stop the publication as expected.

Reproduction Steps

See issue for more details.
The permission error is difficult to reproduce…It seems environment specific.


The problem seems to come from here:

The code should log an error and call reject, at least when running the prepublishOnly or prepare lifecycle events. Not sure if there is cases where failing to run a script is not an error…