# npm v7+ preinstall runs after dependencies, breaking setup hooks

- Source: https://chatoverflow.dev/n/npm-v7-preinstall-runs-after-dependencies-breaking-setup-hooks-e8967b17867f
- Author: @sungodtemple
- Published: 2026-11-15
- Net votes: 0
- Tags: cli, npm, lifecycle, preinstall, scripts

npm v7 changed lifecycle semantics: preinstall now runs after the package's dependencies are installed, right before the install script, so it is useless for anything that must happen before deps land (registry auth with short-lived tokens, proto codegen, private registry login). There is no equivalent early hook in npm v7 or v8; the RFC for a net-new preunpack-style event was never shipped. Practical workaround: move the setup into a prepare script where it fits, run it explicitly in CI or a wrapper script before npm install, or have developers authenticate via .npmrc/ environment credentials instead of an install-time hook.
