Here’s my seed command: node --loader ts-node/esm prisma/seeds.js
I tried many of the other ones, ts-node prisma/seeds.ts
or ts-node --require tsconfig-paths/register prisma/seeds.ts
, none of them worked at least in development. Basically I have a seeds.ts file, and in order to seed I copy it into a seeds.js file.
Here’s where I put the command in my Dockerfile:
# Generate Prisma Client
COPY --link prisma .
RUN npx prisma generate
# # Seeds
RUN npx prisma db seed
# Copy application code
COPY --link . .
And here is the error I get in the terminal:
=> CACHED [build 5/9] RUN npx prisma generate
=> ERROR [build 6/9] RUN npx prisma db seed 2.4s
------
> [build 6/9] RUN npx prisma db seed:
1.765 Running seed command `node --loader ts-node/esm prisma/seeds.js` ...
2.305 (node:39) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
2.305 --import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
2.305 (Use `node --trace-warnings ...` to show where the warning was created)
2.325
2.325 node:internal/process/esm_loader:40
2.325 internalBinding('errors').triggerUncaughtException(
2.325 ^
2.327 Error: Cannot find module '/app/prisma/seeds.js' imported from /app/
2.327 at finalizeResolution (/app/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366:11)
2.327 at moduleResolve (/app/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:801:10)
2.327 at Object.defaultResolve (/app/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
2.327 at /app/node_modules/ts-node/src/esm.ts:218:35
2.327 at entrypointFallback (/app/node_modules/ts-node/src/esm.ts:168:34)
2.327 at /app/node_modules/ts-node/src/esm.ts:217:14
2.327 at addShortCircuitFlag (/app/node_modules/ts-node/src/esm.ts:409:21)
2.327 at resolve (/app/node_modules/ts-node/src/esm.ts:197:12)
2.327 at nextResolve (node:internal/modules/esm/hooks:833:28)
2.327 at Hooks.resolve (node:internal/modules/esm/hooks:278:30)
2.328
2.328 Node.js v20.8.1
2.347
2.347 An error occurred while running the seed command:
2.348 Error: Command failed with exit code 1: node --loader ts-node/esm prisma/seeds.js
------
Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c npx prisma db seed" did not complete successfully: exit code: 1
So I have two questions. What is a proper command to seed with a .ts file and how can I make that command work during deployment?