From 29e76b7e33a47799f9c5f6c4317057a3e032ab46 Mon Sep 17 00:00:00 2001 From: DJP Date: Tue, 21 Apr 2026 08:56:00 -0400 Subject: [PATCH] =?UTF-8?q?Seed=20bundle:=20switch=20CJS=E2=86=92ESM=20so?= =?UTF-8?q?=20import.meta.url=20works?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prisma's generated client calls fileURLToPath(import.meta.url) to locate its query engine binary. In CJS output that's undefined, and the require of the seed bundle blew up before running a line of actual seed code. ESM output (.mjs) runs natively on Node 22, import.meta.url resolves correctly, everything else about the bundle (external npm packages, inlined generated client) stays the same. Co-Authored-By: Claude Opus 4.7 (1M context) --- Dockerfile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0c5d6e6..46d79b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,18 +22,21 @@ RUN npx prisma generate # Build the Next.js app RUN npm run build -# Pre-compile the seed to a self-contained CJS bundle. Runtime then runs -# plain `node prisma/seed-dow.cjs` and avoids the whole tsx+module-resolution -# nightmare: Next.js's standalone node_modules was aggressively reshuffling -# the tree after install, leaving packages like postgres-array with a -# manifest but no index.js. Bundling sidesteps that entirely. +# Pre-compile the seed to a self-contained ESM bundle. Runtime then runs +# plain `node prisma/seed-dow.mjs` and avoids the whole tsx+module- +# resolution nightmare: Next.js's standalone node_modules was aggressively +# reshuffling the tree after install, leaving packages like postgres-array +# with a manifest but no index.js. Bundling sidesteps that entirely. # -# `--packages=external` keeps NPM packages (e.g. bcryptjs, @prisma/*) as -# runtime require() calls so the bundle stays small and native .node files +# ESM (not CJS) because Prisma's generated client uses `import.meta.url` +# for engine detection — that's `undefined` in CJS and crashes on load. +# +# `--packages=external` keeps NPM packages (bcryptjs, @prisma/*) as +# runtime import() calls so the bundle stays small and native .node files # in @prisma/client work normally. RUN npx -y esbuild@0.24 prisma/seed-dow.ts \ - --bundle --platform=node --format=cjs --target=node22 \ - --outfile=prisma/seed-dow.cjs \ + --bundle --platform=node --format=esm --target=node22 \ + --outfile=prisma/seed-dow.mjs \ --packages=external # Production image