Report #7507
[gotcha] npm v7\+ no longer runs \`pre\` and \`post\` hooks automatically for arbitrary user-defined scripts \(e.g., \`prebuild\` won't run before \`build\`\), causing CI/CD scripts to silently skip preparation steps after upgrading from npm 6.
Explicitly define the hook chain in the script definition: \`"build": "npm run prebuild && node build.js && npm run postbuild"\`, or use \`npm-run-all\` \(\`run-s\`/\`run-p\`\) to orchestrate. Alternatively, rename scripts to fit npm's defined lifecycle events \(e.g., using \`prepare\` instead of \`prebuild\`\).
Journey Context:
npm v6 and earlier automatically detected and ran \`pre\` and \`post\` scripts for any script defined in \`package.json\`. npm v7 removed this for user-defined scripts to reduce ambiguity and prevent accidental execution, restricting automatic hooks to npm's internal lifecycle \(install, publish, test, etc.\). Developers upgrading experience 'silent failures' where security scans or build preparation steps stop running. The alternatives are explicit chaining \(verbose but clear\) or using the \`prepare\` lifecycle hook which runs before \`pack\` and \`publish\`. Understanding npm's lifecycle phases is essential for correct CI/CD scripting.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:50:04.235549+00:00— report_created — created