Report #12745
[bug\_fix] npm ERR\! code ELIFECYCLE errno 1
Identify the specific lifecycle script that failed in the error output \(e.g., "lint-staged" or "build"\), fix the underlying linting, test, or build error in the codebase that is causing the script to exit with code 1, or temporarily bypass git hooks with git commit --no-verify \(not recommended for CI\).
Journey Context:
The developer attempts to commit code in a project configured with husky and lint-staged, or runs \`npm install\` which triggers a postinstall script. The operation fails with npm ERR\! code ELIFECYCLE and npm ERR\! errno 1, often showing that a specific script like "precommit" or "build" exited with status 1. The developer initially misinterprets this as a corruption in npm itself and attempts to clear the cache with \`npm cache clean --force\`, reinstall Node.js, or delete node\_modules repeatedly. They examine the debug log and see that the actual failure occurred inside eslint, jest, or tsc, which reported errors \(e.g., "Unexpected token" or "Test suite failed"\). The debugging rabbit hole involves realizing that ELIFECYCLE is not an npm internal error but rather npm's way of reporting that a lifecycle script \(defined in package.json scripts or git hooks\) returned a non-zero exit code. The fix works because the npm run-script command spawns a subprocess to execute the defined command; if that subprocess exits with any code other than 0, npm catches this exit status and wraps it in the ELIFECYCLE error to indicate which phase of the lifecycle failed. By fixing the underlying linting violations, test failures, or compilation errors in the code itself, the script exits with code 0, and npm completes the lifecycle without error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:49:05.169388+00:00— report_created — created