Skip to content

Commit 2896998

Browse files
committed
fix(docker): use .npmrc for build-from-source instead of env var
pnpm does not pass npm_config_* environment variables to install script subprocess environments. The correct way to set npm config for pnpm-spawned install scripts is via .npmrc file, which pnpm reads and merges into the config for all script executions. Change: 'RUN npm_config_build_from_source=true pnpm install' to: 'RUN echo build-from-source=true >> .npmrc && pnpm install'
1 parent bb4fac5 commit 2896998

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

apps/cas/backend/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
3434
RUN npm install -g pnpm@10.11.0
3535

3636
# Install from pruned manifests.
37-
# npm_config_build_from_source skips the prebuild-install download entirely
38-
# and goes straight to node-gyp compilation — necessary because under QEMU
39-
# the prebuild-install download either fails or downloads an incompatible binary.
37+
# Write build-from-source=true to .npmrc so pnpm passes it to better-sqlite3's
38+
# install script (prebuild-install reads this config and skips the prebuilt
39+
# download, going straight to node-gyp compilation with the tools above).
40+
# Setting npm_config_* env vars doesn't work with pnpm — .npmrc is required.
4041
COPY --from=pruner /app/out/json/ .
4142
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
42-
RUN npm_config_build_from_source=true pnpm install --frozen-lockfile
43+
RUN echo 'build-from-source=true' >> .npmrc
44+
RUN pnpm install --frozen-lockfile
4345

4446
# Verify the binary was actually compiled (fail loudly during build if not)
4547
RUN find /app/node_modules/.pnpm -name 'better_sqlite3.node' | grep . || \

apps/template/backend/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ COPY apps/template/backend/package.json ./apps/template/backend/package.json
4848
COPY apps/template/frontend/package.json ./apps/template/frontend/package.json
4949

5050
# Install deps for the template backend only.
51-
# npm_config_build_from_source skips the prebuild-install download entirely
52-
# and goes straight to node-gyp compilation — necessary because under QEMU
53-
# the prebuild-install download either fails or downloads an incompatible binary.
54-
RUN npm_config_build_from_source=true pnpm install --frozen-lockfile --filter @cfxdevkit/template-backend
51+
# Write build-from-source=true to .npmrc so pnpm passes it to better-sqlite3's
52+
# install script (prebuild-install reads this config and skips the prebuilt
53+
# download, going straight to node-gyp compilation with the tools above).
54+
# Setting npm_config_* env vars doesn't work with pnpm — .npmrc is required.
55+
RUN echo 'build-from-source=true' >> .npmrc
56+
RUN pnpm install --frozen-lockfile --filter @cfxdevkit/template-backend
5557

5658
# Verify the binary was actually compiled (fail loudly during build if not)
5759
RUN find /app/node_modules/.pnpm -name 'better_sqlite3.node' | grep . || \

0 commit comments

Comments
 (0)