From 7473589dd8bf77ec905b65bf304c6676e86aebe7 Mon Sep 17 00:00:00 2001 From: Pablo Formoso <95037766+pformoso-deus-ai@users.noreply.github.com> Date: Mon, 2 Mar 2026 23:13:07 +0100 Subject: [PATCH] fix: handle npm git dep installation for GitHub installs npm v11's git dep preparation runs `prepare` before node_modules exist in the temp clone directory, causing TypeScript compilation to fail. Changes: - build.js: skip build gracefully when node_modules absent - package.json: use `node build.js` directly in prepare/prepack for npm compatibility (avoids pnpm dependency during git dep install) Note: postinstall.js already handles all errors internally via main().catch(() => process.exit(0)), so no `|| true` wrapper needed. Install from GitHub with: npm pack github:user/repo#branch npm install -g ./fission-ai-openspec-x.y.z.tgz Co-Authored-By: Claude Opus 4.6 --- build.js | 8 ++++++++ package.json | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build.js b/build.js index fc9aecf94..4487c79b4 100644 --- a/build.js +++ b/build.js @@ -4,6 +4,14 @@ import { execFileSync } from 'child_process'; import { existsSync, rmSync } from 'fs'; import { createRequire } from 'module'; +// When npm installs from a git dep (github:user/repo#branch), it runs +// `prepare` before node_modules exist. Skip gracefully and let `prepack` +// handle the build during the pack phase where deps are available. +if (!existsSync('node_modules')) { + console.log('⏭️ Skipping build (node_modules not yet available)'); + process.exit(0); +} + const require = createRequire(import.meta.url); const runTsc = (args = []) => { diff --git a/package.json b/package.json index 4087d8a2a..580a4d0fa 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "test:ui": "vitest --ui", "test:coverage": "vitest --coverage", "test:postinstall": "node scripts/postinstall.js", - "prepare": "pnpm run build", + "prepare": "node build.js", + "prepack": "node build.js", "prepublishOnly": "pnpm run build", "postinstall": "node scripts/postinstall.js", "check:pack-version": "node scripts/pack-version-check.mjs",