From 670692f46eb19ee89cb924a84ba7fe59b6ebf6f4 Mon Sep 17 00:00:00 2001 From: DJP Date: Mon, 20 Apr 2026 22:59:40 -0400 Subject: [PATCH] Dockerfile: rm -rf the broken pg chain before reinstall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause nailed down: the Next.js standalone tree ships package manifests for the pg driver chain (postgres-array, postgres-bytea etc.) without the corresponding source files. npm's 'version already satisfies, skipping' logic fires on every subsequent install — --force, --no-save, explicit pg@8, all of them. The manifest is there, npm says done. Fix: rm -rf every package in the chain first, then fresh install. Plus a fail-fast check at the end (test -f postgres-array/index.js) so a silent regression surfaces as FATAL in the build log instead of hours later at seed time. Sorry for the runaround. This should've been the first move. Co-Authored-By: Claude Opus 4.7 (1M context) --- Dockerfile | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8947d02..0c5d6e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,25 +57,37 @@ COPY --from=builder /app/prisma.config.ts ./prisma.config.ts COPY --from=builder /app/src/generated ./src/generated # Runtime deps — the Next.js standalone bundle covers the app itself; -# these extras are for: -# prisma — migrate-deploy CLI (run at container start) -# dotenv — prisma.config.ts imports dotenv/config -# @prisma/adapter-pg — the driver the compiled seed.cjs require()s -# bcryptjs — the compiled seed.cjs hashes the admin temp pw -# pg — pulls in postgres-array/bytea/date/interval -# which Next.js's trace sometimes partially includes -# (package.json but no index.js) and then npm's -# "already installed" short-circuit skips +# Runtime deps. The Next.js standalone tree ships with PARTIAL copies of +# the pg driver chain — package.json manifests present but index.js +# missing. npm's "version already satisfies, skipping" logic then fires +# on every subsequent install attempt (including --force), because the +# manifest version check passes and npm never looks at file integrity. # -# --force makes npm overwrite any partial installs the standalone tree -# shipped with, which is the actual root-cause fix for the recurring -# "Cannot find module postgres-array/index.js" crash. -RUN npm install --no-save --force \ +# Nuke the whole pg chain explicitly before reinstalling. Fail-fast at +# the end so if it ever silently regresses we see FATAL in the build +# log, not four hours later at seed time. +RUN rm -rf \ + node_modules/@prisma/adapter-pg \ + node_modules/pg \ + node_modules/pg-cloudflare \ + node_modules/pg-connection-string \ + node_modules/pg-int8 \ + node_modules/pg-numeric \ + node_modules/pg-pool \ + node_modules/pg-protocol \ + node_modules/pg-types \ + node_modules/postgres-array \ + node_modules/postgres-bytea \ + node_modules/postgres-date \ + node_modules/postgres-interval \ + && npm install --no-save \ prisma@7.4.2 \ dotenv@17.3.1 \ @prisma/adapter-pg@7.4.2 \ pg@8 \ - bcryptjs@3 + bcryptjs@3 \ + && test -f node_modules/postgres-array/index.js \ + || (echo "FATAL: postgres-array/index.js still missing after reinstall" >&2 && exit 1) # Create uploads directories for media storage RUN mkdir -p /data/uploads && chown nextjs:nodejs /data/uploads