-
Notifications
You must be signed in to change notification settings - Fork 4
NPM 12 and install scripts
Starting with npm 12 (scheduled for July 2026), npm no longer runs dependency lifecycle scripts by default. This page explains what changes, who is affected, and what to do about it — both as an end user installing a binary addon and as an addon author using this helper.
-
preinstall/install/postinstallscripts of dependencies do not run unless the dependency is explicitly allowed. - The implicit
node-gyp rebuildfor packages with abinding.gypdoes not run either — so the classic build-from-source flow is gated the same way as the prebuilt download. -
preparescripts of git / file / link dependencies are gated as well.
npm 11.16.0 (May 2026) introduced the same machinery in advisory mode: scripts still run, but an end-of-install summary names every package with unreviewed install scripts. npm 12 turns that into a hard block.
install-from-cache runs as the consuming addon's install script. Under npm 12 defaults, a plain npm install <addon> fails with ESTRICTALLOWSCRIPTS before running anything — neither the prebuilt-artifact download nor the node-gyp fallback fires, and nothing is installed (the failure is atomic). Nothing in this helper can bypass the gate: it is a consumer-side security decision, the same one that hits every native addon (Playwright, Puppeteer, Electron, sharp, ...).
Approve the addon once per project — npm records the approval in the allowScripts field of your package.json. The simplest flow is to pre-approve before installing:
npm pkg set allowScripts.some-addon=true --json
npm install some-addonor equivalently, add to your project's package.json by hand:
{
"allowScripts": {
"some-addon": true
}
}On npm 11.16+ (advisory mode, before npm 12) npm install some-addon still runs the scripts and just warns — there npm approve-scripts some-addon after the install silences the warning and future-proofs the project.
Under npm 12, recovering after the ESTRICTALLOWSCRIPTS failure takes an extra step, because npm approve-scripts only matches installed packages and the failed install left nothing behind:
npm install some-addon --ignore-scripts # install with scripts skipped
npm approve-scripts some-addon # record the approval
npm rebuild some-addon # run the addon's install script nowUseful details:
-
Approvals are version-pinned by default —
npm approve-scripts some-addonwrites"some-addon@1.2.3": true, so a version update re-prompts. Usenpm approve-scripts --no-allow-scripts-pin some-addonto approve all versions. -
npm approve-scripts --allow-scripts-pendinglists the packages awaiting review without changing anything. -
npm deny-scripts some-addonrecords an explicit refusal — the install then succeeds with the addon's scripts silently skipped, and you get the missing-binary error at runtime.
-
Document the approval step in your install instructions — a one-liner with
npm approve-scripts <your-package>next to yournpm install <your-package>line. A user who knows the command fixes the problem in seconds; a user who doesn't gets a cryptic missing-.nodeerror at runtime. - Consider the failure mode in your loading code: if your addon prints a helpful message when its binary is missing ("run
npm approve-scripts <your-package>andnpm rebuild <your-package>"), the npm-12 experience becomes self-explanatory. - There is nothing to change on the helper's side — the gate fires before any script of your package runs. Watch npm for package-side metadata that could smooth approval (pnpm's
onlyBuiltDependenciesis the precedent); none exists yet.