Seed bundle: switch CJS→ESM so import.meta.url works
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) <noreply@anthropic.com>
This commit is contained in:
parent
670692f46e
commit
29e76b7e33
1 changed files with 12 additions and 9 deletions
21
Dockerfile
21
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue