Repository navigation
Description
Where
examples/git-hooks/install.mjs's own doc comment, and the lint/format precommit-hook docs, wire the pre-commit hook installer as:
"scripts": { "prepare": "node .githooks/install.mjs" }What happens
prepare runs on npm install, npm pack, and npm publish — not just local dev installs. .githooks/ is correctly excluded from consumers' "files" (it's dev-only tooling; a consumer's node_modules/<pkg>/ has no .git to hook into, and install.mjs already self-guards for exactly that case via if (repoRoot.split(sep).includes("node_modules")) process.exit(0)).
But npm publish/npm pack run lifecycle scripts against the packed tree — only "files"-listed content — so .githooks/install.mjs isn't there to find. Node fails at module resolution before the installer's own no-op guards ever run:
node:internal/modules/cjs/loader:1520
Error: Cannot find module '.../package-contents/.githooks/install.mjs'
npm error command failed
npm error command sh -c node .githooks/install.mjs
This aborts the publish outright — both the npm and GitHub Packages publish steps fail identically, every time, for every repo carrying the bare form, regardless of whether the repo has ever actually attempted a real publish before (CI never surfaces this — it only appears on an actual npm publish/npm pack run).
Repro
Reproduced on CLDMV/droidsock's first real v1.0.0 publish attempt (2026-09-01): publish-package / 📦 Publish Package / 📦 Publish to NPM and .../📦 Publish to GitHub Packages both failed identically with the error above. The package had never been published before, so this had gone undetected through the entire onboarding + several PR merges — .githooks/install.mjs running fine locally and in CI (both real dev checkouts with .git present) gave no signal that publish would fail.
Fix
"scripts": { "prepare": "node -e \"import('./.githooks/install.mjs').catch(()=>{})\"" }Verified both paths: a normal dev checkout still installs the hook (prints ✓ installed .git/hooks/pre-commit), and running the same command from a directory with no .githooks/ present exits 0 silently instead of crashing.
Ask
- Update
examples/git-hooks/install.mjs's own doc comment (anddocs/conventions/lint-format-precommit.md, if it repeats the wiring snippet) to the corrected form. - Any already-onboarded repo carrying the bare form has this same latent bug and won't discover it until its own first real publish.
Activity
cldmv-bot commentedon Sep 2, 2026
Closed in v4.25.0 — resolved by #254.