Skip to content

Commit 84ee318

Browse files
fix: resolve pnpm symlinks for Vercel serverless function packaging
Install external dependencies (pino, pino-pretty, @libsql/client) via npm into api/node_modules/ during the build step. This creates real directories (no symlinks) that Vercel can properly package for the serverless function. - Updated build-vercel.sh to install external deps in api/node_modules/ - Updated vercel.json includeFiles to api/node_modules/** - Added @libsql/client to esbuild EXTERNAL list - Added api/node_modules/ and public/ to .gitignore Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/a2378bd5-dff3-42d5-bf08-1dff787cf351 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 61a4b20 commit 84ee318

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

apps/server/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Build artifacts
22
dist/
33
.turbo/
4+
public/
45

56
# Bundled API handler (generated during Vercel build)
67
api/_handler.js
78
api/_handler.js.map
9+
api/node_modules/
810

911
# Node modules
1012
node_modules/

apps/server/scripts/build-vercel.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ set -euo pipefail
88
# - esbuild bundles server/index.ts → api/_handler.js (self-contained bundle)
99
# - The committed .js wrapper re-exports from _handler.js at runtime
1010
# - Studio SPA is built and copied to public/ for serving the UI
11+
# - External dependencies installed in api/node_modules/ (no symlinks)
1112
#
1213
# Steps:
1314
# 1. Build the project with turbo (includes studio)
1415
# 2. Bundle the API serverless function (→ api/_handler.js)
1516
# 3. Copy studio dist files to public/ for UI serving
17+
# 4. Install external deps in api/node_modules/ (resolve pnpm symlinks)
1618

1719
echo "[build-vercel] Starting server build..."
1820

@@ -36,4 +38,26 @@ else
3638
echo "[build-vercel] ⚠ Studio dist not found (skipped)"
3739
fi
3840

41+
# 4. Install external dependencies in api/node_modules/ (no symlinks)
42+
# pnpm uses symlinks in node_modules/, which Vercel's serverless function
43+
# packaging cannot handle ("invalid deployment package" error).
44+
# We use npm to install external packages as real files next to the handler.
45+
echo "[build-vercel] Installing external dependencies for serverless function..."
46+
cat > api/_package.json << 'DEPS'
47+
{
48+
"private": true,
49+
"dependencies": {
50+
"@libsql/client": "0.14.0",
51+
"pino": "10.3.1",
52+
"pino-pretty": "13.1.3"
53+
}
54+
}
55+
DEPS
56+
cd api
57+
mv _package.json package.json
58+
npm install --production --no-package-lock --ignore-scripts 2>&1 | tail -3
59+
rm package.json
60+
cd ..
61+
echo "[build-vercel] ✓ External dependencies installed in api/node_modules/"
62+
3963
echo "[build-vercel] Done. Static files in public/, serverless function in api/[[...route]].js → api/_handler.js"

apps/server/scripts/bundle-api.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const EXTERNAL = [
2727
'tedious',
2828
// macOS-only native file watcher
2929
'fsevents',
30+
// LibSQL client — has native bindings, must remain external for Vercel
31+
'@libsql/client',
3032
// Logging libraries - use dynamic require, must be external
3133
'pino',
3234
'pino-pretty',

apps/server/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"api/**/*.js": {
1414
"memory": 1024,
1515
"maxDuration": 60,
16-
"includeFiles": "node_modules/{pino,pino-pretty}/**"
16+
"includeFiles": "api/node_modules/**"
1717
}
1818
},
1919
"headers": [

0 commit comments

Comments
 (0)