Skip to content

examples/git-hooks: documented "prepare" wiring crashes npm publish/pack (file excluded from "files") #250

Closed

Description

@Shinrai

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 (and docs/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

  1. added
    type: bug
    type: documentation
    priority: high
    on Sep 1, 2026
  2. added theissue type on Sep 2, 2026
  3. cldmv-bot commented on Sep 2, 2026

    @cldmv-bot
    Contributor

    Closed in v4.25.0 — resolved by #254.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: hightype: bugtype: documentation

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions