Skip to content

Commit 666d690

Browse files
committed
fix: compile better-sqlite3 via node-gyp directly in pnpm virtual store
npm/pnpm rebuild only target packages with a root-level node_modules symlink. better-sqlite3 is a transitive dep (backend -> executor -> services), so pnpm only places it in .pnpm/ with no root symlink — both rebuild commands silently no-op. Fix: install node-gyp globally, find the package precisely in .pnpm/ using find ... | grep '/node_modules/better-sqlite3$' then run node-gyp rebuild --release directly there. This is arch-agnostic and works regardless of hoisting behavior in turbo prune output.
1 parent 54983cf commit 666d690

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

apps/cas/backend/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
3232

3333
RUN npm install -g pnpm@10.11.0
3434

35-
# Install from pruned manifests, then explicitly rebuild better-sqlite3 from
36-
# source. npm rebuild (not pnpm) traverses transitive deps and ships node-gyp,
37-
# so it compiles the native addon regardless of dep depth.
35+
# Install from pruned manifests, then compile better-sqlite3 by finding it
36+
# directly in the pnpm virtual store and running node-gyp there.
37+
# npm/pnpm rebuild both only target hoisted root-level deps; better-sqlite3 is
38+
# transitive so it lives exclusively in .pnpm/ with no root symlink.
3839
COPY --from=pruner /app/out/json/ .
3940
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
4041
RUN pnpm install --frozen-lockfile
41-
RUN npm rebuild better-sqlite3 --build-from-source
42+
RUN npm install -g node-gyp \
43+
&& BSQ=$(find /app/node_modules/.pnpm -name 'better-sqlite3' -type d \
44+
| grep '/node_modules/better-sqlite3$' | head -1) \
45+
&& echo "Compiling better-sqlite3 in: $BSQ" \
46+
&& test -n "$BSQ" \
47+
&& cd "$BSQ" && node-gyp rebuild --release
4248

4349
# Verify the binary was compiled (hard fail during build if missing)
4450
RUN find /app/node_modules/.pnpm -name 'better_sqlite3.node' | grep . || \

apps/template/backend/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ COPY apps/cas/frontend/package.json ./apps/cas/frontend/package.json
4646
COPY apps/template/backend/package.json ./apps/template/backend/package.json
4747
COPY apps/template/frontend/package.json ./apps/template/frontend/package.json
4848

49-
# Install deps, then explicitly rebuild better-sqlite3 from source.
50-
# npm rebuild (not pnpm) traverses transitive deps and ships node-gyp,
51-
# so it compiles the native addon regardless of dep depth.
49+
# Install deps, then compile better-sqlite3 by finding it directly in the
50+
# pnpm virtual store and running node-gyp there.
51+
# npm/pnpm rebuild both only target hoisted root-level deps; better-sqlite3 is
52+
# transitive so it lives exclusively in .pnpm/ with no root symlink.
5253
RUN pnpm install --frozen-lockfile --filter @cfxdevkit/template-backend
53-
RUN npm rebuild better-sqlite3 --build-from-source
54+
RUN npm install -g node-gyp \
55+
&& BSQ=$(find /app/node_modules/.pnpm -name 'better-sqlite3' -type d \
56+
| grep '/node_modules/better-sqlite3$' | head -1) \
57+
&& echo "Compiling better-sqlite3 in: $BSQ" \
58+
&& test -n "$BSQ" \
59+
&& cd "$BSQ" && node-gyp rebuild --release
5460

5561
# Verify the binary was compiled (hard fail during build if missing)
5662
RUN find /app/node_modules/.pnpm -name 'better_sqlite3.node' | grep . || \

0 commit comments

Comments
 (0)