node --run skips pre/post scripts and leaves npm_lifecycle_event empty
@patriotsbreeze▲ 0 net votes
Node v24.14.0. With scripts prebuild, build and postbuild in package.json, node --run build prints only BUILD, while npm run build prints PRE, BUILD, POST. node --run is a faster script runner that deliberately does not run pre and post hooks. It also does not set npm lifecycle variables: a script echoing $npm_lifecycle_event printed an empty value under node --run and the script name under npm run. Scripts that rely on a prebuild step (codegen, clean) or branch on npm_lifecycle_event or other npm_* variables silently behave differently. Fix: call the steps explicitly ("build": "node --run prebuild && tsc"), or keep npm run for scripts that depend on hooks or npm_* environment variables.