Skip to content

Commit 0fa5419

Browse files
fix: copy native modules from monorepo root node_modules for pnpm strict mode on Vercel
Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/5da7c570-c9a4-4a8d-93d4-bcb11dad0da9 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 1bc22cd commit 0fa5419

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
`events` without the "Dynamic require is not supported" error.
2222
Added `functions.includeFiles` in `vercel.json` to include native addons
2323
(`better-sqlite3`, `@libsql/client`) that esbuild cannot bundle.
24+
Added a build step to copy native external modules from the monorepo root
25+
`node_modules/` into the studio's local `node_modules/`, since pnpm's strict
26+
mode (unlike hotcrm's `shamefully-hoist`) doesn't symlink transitive native
27+
dependencies into app-level `node_modules/`.
2428
Updated rewrites to match: `/api/:path*``/api/[[...route]]`.
2529
- **Studio CORS error on Vercel temporary/preview domains** — Changed
2630
`VITE_SERVER_URL` from hardcoded `https://play.objectstack.ai` to `""`

apps/studio/scripts/build-vercel.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,41 @@ cd apps/studio
2828
# 2. Bundle API serverless function
2929
node scripts/bundle-api.mjs
3030

31-
# 3. Copy Vite build output to public/ for static file serving
31+
# 3. Copy native/external modules into local node_modules for Vercel packaging.
32+
#
33+
# Unlike hotcrm (which uses shamefully-hoist=true), this monorepo uses pnpm's
34+
# default strict node_modules structure. Transitive native dependencies like
35+
# better-sqlite3 only exist in the monorepo root's node_modules/.pnpm/ virtual
36+
# store — they're NOT symlinked into apps/studio/node_modules/.
37+
#
38+
# The vercel.json includeFiles pattern references node_modules/ relative to
39+
# apps/studio/, so we must copy the actual module files here for Vercel to
40+
# include them in the serverless function's deployment package.
41+
echo "[build-vercel] Copying external native modules to local node_modules..."
42+
for mod in better-sqlite3; do
43+
src="../../node_modules/$mod"
44+
if [ -e "$src" ]; then
45+
dest="node_modules/$mod"
46+
mkdir -p "$(dirname "$dest")"
47+
cp -rL "$src" "$dest"
48+
echo "[build-vercel] ✓ Copied $mod"
49+
else
50+
echo "[build-vercel] ⚠ $mod not found at $src (skipped)"
51+
fi
52+
done
53+
# Copy the @libsql scope (client + its sub-dependencies like core, hrana-client)
54+
if [ -d "../../node_modules/@libsql" ]; then
55+
mkdir -p "node_modules/@libsql"
56+
for pkg in ../../node_modules/@libsql/*/; do
57+
pkgname="$(basename "$pkg")"
58+
cp -rL "$pkg" "node_modules/@libsql/$pkgname"
59+
done
60+
echo "[build-vercel] ✓ Copied @libsql/*"
61+
else
62+
echo "[build-vercel] ⚠ @libsql not found (skipped)"
63+
fi
64+
65+
# 4. Copy Vite build output to public/ for static file serving
3266
rm -rf public
3367
mkdir -p public
3468
cp -r dist/* public/

0 commit comments

Comments
 (0)