Every npm 12 migration guide stops in the same place: run npm approve-scripts, commit the allowScripts block, done. Nobody writes about the week after, when npm ci exits 0, the pipeline is green, and the container falls over on first request with Cannot find module '../build/Release/bcrypt_lib.node'.
TL;DR: npm 12 skips an unapproved install script with a warning and still exits 0, so a hollow node_modules ships green. Read the error string first: Cannot find module '../build/Release/*.node' is a blocked compile step and wants allowScripts plus npm rebuild, while a missing platform package wants a regenerated lockfile. Gate it permanently with npm ci --strict-allow-scripts and a node -e require loop in the final Docker stage.
That happens because of a deliberate design choice, documented in GitHub's June 9 changelog for npm v12: an unapproved install script is skipped with a warning, and the install still succeeds. Socket's write-up of the release describes the same default as the softer of the two options npm considered. Your build ends up producing a node_modules tree that is structurally complete and functionally hollow.
Three unrelated failures print near-identical "this native module won't load" output, and npm 12 only added the third one a few months ago, so threads, docs and model answers all run them together. Before any of this, get your approvals into the repo: the npm allowScripts warning walkthrough covers the schema and the warning window. What follows is what happens after that, plus the CI gates that catch each cause before a deploy does. Tips 1 to 3 are the triage, and everything after assumes you did it.
| Symptom | Real cause | The fix that works |
|---|---|---|
Cannot find module '../build/Release/*.node' | install script or implicit node-gyp rebuild skipped | allowScripts plus npm rebuild |
Could not load the "sharp" module using the linux-x64 runtime | platform optional dep absent from the lockfile | regenerate package-lock.json |
Error loading shared library libstdc++.so.6 | glibc binary running on musl | rebuild in the runtime image |
Most teams meet this in a running container rather than in CI, which an unsequenced rollout makes close to inevitable. For the estate-level version of the same problem, see what breaks after CI goes green.
Which error string are you actually holding?
1. Read the error string before you touch allowScripts. Cannot find module '../build/Release/foo.node' means a compile step never ran, which is an npm 12 problem. Could not load the "sharp" module using the linux-x64 runtime and Cannot find module '@rollup/rollup-linux-x64-gnu' mean a whole package is absent from the tree, and no approval list will conjure it back. Teams burn entire afternoons adding entries to allowScripts for that second class. Two commands, two different jobs: approve-scripts versus --allow-scripts draws the line.
2. Approving sharp accomplishes nothing. sharp's own install documentation states that its prebuilt binaries arrive through optional dependencies and asks you to ensure your package manager is configured to install optional dependencies. There is no install script there to approve. The packages that genuinely need approval are the node-gyp and prebuild-install crowd: bcrypt, better-sqlite3, canvas, node-pty, dtrace-provider. Check which family you are in before editing anything:
node -p "require('./node_modules/sharp/package.json').scripts || 'no scripts'"
3. Sweep for binding.gyp files, because scripts.install misses half of them. npm 12 blocks the implicit node-gyp rebuild that npm runs for any dependency shipping a binding.gyp, even when that package declares no install script at all. A jq pass over scripts.install in your dependency manifests will report a clean tree and be wrong:
find node_modules -maxdepth 3 -name binding.gyp -printf '%h\n' | sed 's|node_modules/||'
Every path that prints is a package that compiles at install time and needs an allowScripts decision.
How do you make CI fail instead of warn?
4. Make CI fail loudly with --strict-allow-scripts. The default warning is written for a human watching a terminal scroll past, which describes nobody in your pipeline. Strict mode turns the same condition into an ESTRICTALLOWSCRIPTS failure:
npm ci --strict-allow-scripts
5. Expect strict mode to reject a package your pending list cannot show you. npm/cli issue #9562 documents exactly this: on a Linux runner, npm ci --strict-allow-scripts rejected fsevents@2.3.3 for lacking approval, while npm approve-scripts --allow-scripts-pending never listed it, because the package is a Darwin-only optional dependency and the pending scan skipped it. It was closed by PR #9597. If CI fails on a package your laptop refuses to list, approve it by name explicitly and move on rather than hunting for a config error you do not have.
What check survives a green pipeline?
6. Make the build load every native module, because exit code 0 proves nothing. Add a smoke step that does what production does on first request. Two lines converts a silent skip into a red build:
node -e 'for (const m of ["bcrypt","better-sqlite3","canvas"]) { require(m); console.log("ok", m) }'
Keep the module list in a file next to your Dockerfile and generate it from tip 3's binding.gyp sweep so it stays honest as dependencies change.
7. Run that smoke test in the runtime stage. A .node file compiled in a node:24-bookworm builder and copied into node:24-alpine loads fine in the builder and dies in the runtime image with Error loading shared library libstdc++.so.6. That is the third row of the table. npm 12 never touched this behaviour, yet the failure gets blamed on npm 12 all over the place this quarter because the timing lines up. Put the node -e require loop as the last RUN in the final stage, so it links against the same libc that will serve traffic.
Why does approving a package not fix the tree?
8. Approving a package does not retroactively build it. allowScripts is consulted during installation, so editing package.json afterwards leaves the empty tree exactly as it was. Locally, run npm rebuild <pkg> to recover. In CI, distrust any cached node_modules and start from a clean tree:
npm approve-scripts better-sqlite3 --no-allow-scripts-pin
npm rebuild better-sqlite3
9. Pinned allowScripts entries expire the moment Renovate bumps. An entry like "better-sqlite3@12.6.0": true covers that exact version. The next dependency bump produces a package matching nothing in your allowlist, the script is skipped, and the failure surfaces a deploy later on a PR that "only touched dependencies". Use name-only keys via --no-allow-scripts-pin for packages you have already reviewed, and save pinned keys for the genuinely untrusted ones where forcing a re-review is the point. The package.json schema breakdown has the key forms npm accepts.
What if the platform binary never reached the lockfile?
10. Fix a missing platform binary at the lockfile. npm/cli issue #4828 explains the mechanism behind Cannot find module '@rollup/rollup-linux-x64-gnu': regenerating package-lock.json while node_modules already exists records only the optional variants for the machine doing the regenerating. Committed from a Mac, the Linux runner then skips a dependency it can never resolve. The repair is destructive and has to be:
rm -rf node_modules package-lock.json && npm install
git add package-lock.json
For cross-platform lockfiles, sharp's docs point at --os, --cpu and --libc, so npm install --cpu=x64 --os=linux --libc=musl sharp forces the variant your Alpine image will look for.
11. Turn on --foreground-scripts when a build works but takes suspiciously long. prebuild-install quietly falls back to compiling from source when no prebuilt binary matches the platform, and npm hides that output by default. npm ci --foreground-scripts puts the compiler chatter in the CI log, which is how you discover a runner spent four minutes building a binary you assumed was downloaded.
Is something overriding allowScripts entirely?
12. Hunt down every leftover ignore-scripts. --ignore-scripts outranks allowScripts, and teams that hardened against supply-chain attacks in 2025 tend to have ignore-scripts=true sitting in a repo .npmrc, an NPM_CONFIG_IGNORE_SCRIPTS env var in the pipeline, or baked into a hardened base image. Every approval you commit gets ignored, and the warning that would normally tip you off never prints. Audit all three surfaces before you conclude npm is broken:
npm config get ignore-scripts
grep -rn "ignore.scripts" .npmrc .github/ Dockerfile* 2>/dev/null
env | grep -i npm_config
FAQ
Why does npm ci exit 0 when the install script never ran?
npm 12 treats a blocked install script as a warning, not an error. GitHub's v12 changelog documents the choice: the script is skipped and the install still succeeds, leaving a tree that looks complete with no compiled binary in it. npm ci --strict-allow-scripts promotes that warning to an ESTRICTALLOWSCRIPTS failure.
Do I need to approve sharp in allowScripts?
No. sharp ships prebuilt binaries through optional dependencies, so there is no install script to approve. A sharp failure reads Could not load the "sharp" module using the linux-x64 runtime and points at your lockfile. Approval lists matter for the node-gyp and prebuild-install packages.
Does editing allowScripts fix a tree that is already installed?
No. npm reads allowScripts during installation only, so an approval added afterwards changes nothing on disk. Run npm rebuild <pkg> locally, and in CI drop the cached node_modules first.
Why does CI reject a package that npm approve-scripts never listed?
npm/cli issue #9562 covers it: a Linux runner rejected fsevents@2.3.3 while the pending scan skipped it as a Darwin-only optional dependency. PR #9597 closed that. Until you are on the fixed build, approve the package by name.
Should allowScripts keys be pinned to a version?
Pin the packages where a bump should force a fresh review. For everything already reviewed, name-only keys via --no-allow-scripts-pin avoid a silent skip the next time Renovate moves a version.
Wrap-up
Keep one habit from this list: make CI load every native module inside the runtime image. Approval lists drift as dependencies bump, lockfiles get regenerated on the wrong laptop, base images change libc, and all three failures share the property that npm reports success. Put a node -e require loop in the final stage and every one of the three gets caught there.
If you would rather hand the whole npm 12 cutover to someone who has already walked these three failures, that is work I take on.
If the tree itself is your real problem rather than the scripts, the npm edgesOut crash breakdown separates that family. pnpm users reach the same wall through a different door, covered in the pnpm 12 upgrade traps.

Comments
Be the first to comment.