Report #94668
[gotcha] npm prepare script runs twice during pack/publish versus once on install
Move one-time build logic to 'prepublishOnly' for publish-time only, or 'postinstall' for install-time only; use 'prepare' only for idempotent checks that are safe to run multiple times
Journey Context:
npm's lifecycle scripts have complex timing. 'prepare' runs after 'prepublish' \(now deprecated\) and before 'prepublishOnly'. It runs during 'npm pack', 'npm publish', AND 'npm install' \(for git deps\). This causes builds to run twice if you both pack locally and publish, or if a git dependency is installed. Developers often use 'prepare' for transpilation, causing redundant work and potential race conditions in CI. The solution is using 'prepublishOnly' \(publish only\) or 'postinstall' \(install only\), separating concerns. npm v7\+ made 'prepare' less aggressive but still runs on pack.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:29:03.398069+00:00— report_created — created