From 943a9374b4887929f2a5037828090c467229bbff Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Thu, 12 Mar 2026 10:42:59 -0300 Subject: [PATCH] fix: permanent @swc/helpers MODULE_NOT_FOUND fix (#crash) prepublish.mjs: explicitly copy @swc/helpers into standalone app/node_modules before packaging. npm tarball will always include it. postinstall.mjs: fallback copy of @swc/helpers from root node_modules into app/node_modules/@swc/ when missing after npm install -g. Fixes server crash after npm install -g omniroute. --- CHANGELOG.md | 12 +++++++++++- docs/openapi.yaml | 2 +- package.json | 2 +- scripts/postinstall.mjs | 25 +++++++++++++++++++++++++ scripts/prepublish.mjs | 12 ++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 550dc586a3..8d38f2a13d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- -## [2.3.4] — 2026-03-12 +## [2.3.5] — 2026-03-12 + +> ### Hotfix: Permanent @swc/helpers MODULE_NOT_FOUND Fix + +### 🐛 Bug Fixes + +- **`@swc/helpers` MODULE_NOT_FOUND crash on `npm install -g`** — Next.js standalone tracer does not always include `@swc/helpers` in `app/node_modules/`, causing an immediate server crash after install. Fixed in two layers: + - `scripts/prepublish.mjs` — now explicitly copies `@swc/helpers` from root `node_modules/` into the standalone `app/node_modules/` before packaging. The npm tarball will always include it from now on. + - `scripts/postinstall.mjs` — added a fallback that copies `@swc/helpers` from root into `app/node_modules/@swc/` if it's missing after install. Handles older versions and edge cases. + +--- > ### UI Polish — Endpoint Music Section, Always-Visible Buttons & Provider Logos diff --git a/docs/openapi.yaml b/docs/openapi.yaml index aedd661bd4..7c63eab310 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: OmniRoute API - version: 2.3.4 + version: 2.3.5 description: | OmniRoute is a local-first AI API proxy router. It provides an OpenAI-compatible endpoint that routes requests to multiple AI providers with load balancing, diff --git a/package.json b/package.json index 65037d227e..c4915c050d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "omniroute", - "version": "2.3.4", + "version": "2.3.5", "description": "Smart AI Router with auto fallback — route to FREE & cheap models, zero downtime. Works with Cursor, Cline, Claude Desktop, Codex, and any OpenAI-compatible tool.", "type": "module", "bin": { diff --git a/scripts/postinstall.mjs b/scripts/postinstall.mjs index 12fd4436e5..6873ac411d 100644 --- a/scripts/postinstall.mjs +++ b/scripts/postinstall.mjs @@ -113,3 +113,28 @@ if (process.platform === "darwin") { console.warn(" If build tools are missing: xcode-select --install"); } console.warn(""); + +// ── @swc/helpers fix ──────────────────────────────────────────────────────── +// Next.js standalone tracer doesn't always include @swc/helpers in app/node_modules/, +// causing a MODULE_NOT_FOUND crash at runtime. Copy it from root node_modules if needed. +const swcHelpersApp = join(ROOT, "app", "node_modules", "@swc", "helpers"); +const swcHelpersRoot = join(ROOT, "node_modules", "@swc", "helpers"); + +if (!existsSync(swcHelpersApp)) { + if (existsSync(swcHelpersRoot)) { + try { + const { cpSync } = await import("node:fs"); + mkdirSync(join(ROOT, "app", "node_modules", "@swc"), { recursive: true }); + cpSync(swcHelpersRoot, swcHelpersApp, { recursive: true }); + console.log(" ✅ @swc/helpers copied to standalone app/node_modules.\n"); + } catch (err) { + console.warn(` ⚠️ Could not copy @swc/helpers: ${err.message}`); + console.warn( + " Try manually: cp -r node_modules/@swc/helpers app/node_modules/@swc/helpers\n" + ); + } + } else { + console.warn(" ⚠️ @swc/helpers not found in root node_modules either."); + console.warn(" Try: npm install --save-exact @swc/helpers@0.5.19\n"); + } +} diff --git a/scripts/prepublish.mjs b/scripts/prepublish.mjs index 381181e41e..a64f79cc9f 100644 --- a/scripts/prepublish.mjs +++ b/scripts/prepublish.mjs @@ -122,6 +122,18 @@ if (existsSync(sharedApiKey)) { // ── Step 10: Ensure data/ directory exists ────────────────── mkdirSync(join(APP_DIR, "data"), { recursive: true }); +// ── Step 10.5: Copy @swc/helpers into standalone ─────────── +// Next.js standalone tracer sometimes omits @swc/helpers from app/node_modules/, +// causing MODULE_NOT_FOUND at runtime. Always copy it explicitly. +const swcHelpersSrc = join(ROOT, "node_modules", "@swc", "helpers"); +const swcHelpersDst = join(APP_DIR, "node_modules", "@swc", "helpers"); +if (existsSync(swcHelpersSrc) && !existsSync(swcHelpersDst)) { + console.log(" 📋 Copying @swc/helpers to standalone app/node_modules..."); + mkdirSync(join(APP_DIR, "node_modules", "@swc"), { recursive: true }); + cpSync(swcHelpersSrc, swcHelpersDst, { recursive: true }); + console.log(" ✅ @swc/helpers included in standalone build."); +} + // ── Done ─────────────────────────────────────────────────── const appPkg = join(APP_DIR, "package.json"); if (existsSync(appPkg)) {