Skip to content

Fix: root prepare must not fail npm install in a build context - #194

Merged
vivek7405 merged 1 commit into
mainfrom
fix/prepare-resilient-in-build
Jun 1, 2026
Merged

vivek7405 merged 1 commit into
mainfrom
fix/prepare-resilient-in-build

Conversation

@vivek7405

Copy link
Copy Markdown
Collaborator

Summary

Hotfix for a production outage: all four Railway services (example-blog, website, docs, ui-website) fail to deploy. They build from the monorepo root, and the build dies at npm install:

[16/26] RUN npm install --no-audit --no-fund
Error: Cannot find module '/app/scripts/git-worktree-safe.mjs'
npm error command sh -c node scripts/git-worktree-safe.mjs
Build Failed

Root cause: #189 changed the root prepare to a bare node scripts/git-worktree-safe.mjs. In a Docker / Nixpacks build, npm install runs after COPY package.json but before the repo is fully copied, so scripts/ is not in the image yet. node exits 1 (module not found) and the build fails. The previous prepare ended in || true, so it never failed the install.

Fix

Restore the guard:

"prepare": "node scripts/git-worktree-safe.mjs 2>/dev/null || true"

A missing script (build context) or any git error is now a no-op that exits 0, so npm install never fails. The dev-machine self-heal still runs when the script is present.

Test plan

  • New regression test runs the ACTUAL prepare command in a scriptless temp dir and asserts exit 0 (test/repo-health/prepare-build-safe.test.mjs).
  • Counterfactual confirmed: the unguarded command exits 1 ("Cannot find module") in a scriptless dir, which is the exact build failure; the guarded command exits 0.
  • Verified the script still heals + exits 0 when present (dev).

Definition of done

  • Tests: Updated (new build-context regression test).
  • Docs: N/A. One-line restoration of the prior resilient pattern; no surface change.
  • Version bump: N/A. Root monorepo package.json (private, not published).

Expedited review given the live outage (one-line restoration of a known-good pattern with a proven counterfactual).

The prepare runs `node scripts/git-worktree-safe.mjs`. In a Docker / Nixpacks
build, npm install runs after COPY package.json but before the repo is fully
copied, so scripts/ is not in the image yet: node exits 1 (module not found)
and the build fails. This broke all four deployed services (#189 introduced
the unguarded prepare; the prior one ended in `|| true`).

Restore the guard: `node scripts/git-worktree-safe.mjs 2>/dev/null || true`,
so a missing script (or any git error) is a no-op and never fails the install.
The dev-machine self-heal still runs when the script is present. Regression
test runs the actual prepare command in a scriptless temp dir and asserts
exit 0.
@vivek7405 vivek7405 self-assigned this Jun 1, 2026
@vivek7405
vivek7405 merged commit e72bd94 into main Jun 1, 2026
4 of 5 checks passed
@vivek7405
vivek7405 deleted the fix/prepare-resilient-in-build branch June 1, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant