prisma: prisma db seed doesn't correctly support `"type": "module"`
Problem
When you enable module resolution with "type": "module"
on your projet the prisma db seed
command fail due to ts-node resolution.
➜ yarn prisma db seed --preview-feature
yarn run v1.22.10
$ /path-to-my-project/node_modules/.bin/prisma db seed --preview-feature
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma
Running ts-node "prisma/seed.ts" ...
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /path-to-my-project/play-prisma-sqlite/prisma/seed.ts
at new NodeError (node:internal/errors:329:5)
at Loader.defaultGetFormat [as _getFormat] (node:internal/modules/esm/get_format:71:15)
at Loader.getFormat (node:internal/modules/esm/loader:104:42)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:31)
at Loader.import (node:internal/modules/esm/loader:176:17)
at Object.loadESM (node:internal/process/esm_loader:68:5)
Error: Command failed with exit code 1: ts-node "prisma/seed.ts"
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Suggested solution
When "type": "module"
is detected: instead of running ts-node "prisma/seed.ts"
you can use the node loader node --loader ts-node/esm "prisma/seed.ts"
Alternatives
N/A
Additional context
Project example https://github.com/ghoullier/esm-prisma-seed
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 21 (4 by maintainers)
TSX worked for me in sveltekit
yarn add -D tsx
“prisma”: { “seed”: “tsx prisma/seed.ts” }
Had the same problem, but the ts-node esm flag fixed it for me:
ts-node --esm prisma/seed.ts
This is temp case, you can run seed, but
--preview-feature
not work:If your seed file in at your project
prisma/seed.ts
.1 - Install esbuild in your project
2 - Add
seed
in yourpackage.json
scripts:3 - Run seed script
It works in my project, hope you can run it.
You can just tell ts-node to use CJS module resolution when transpiling
seed.ts
by passing--compilier-options {"module":"CommonJS"}
in your seed command in yourpackage.json
.I was running into the same issues but had success with
tsx
.Svelte version:
"svelte": "^4.0.5",
Still running into this issue with the latest version of Prisma while using Sveltekit. I’ve installed all the prerequisites.
I’ve tried it multiple ways
and
Not sure what else to try here.
After trying for a few hours, this also worked for me with typescript. I’m also using SvelteKit.
I’m using Vue3 and Vite (not Svelte) and the
tsx
solution worked for me.Only solution that works for me on Next 13.4.12
I am facing the same issue with Prisma 3.11.1 but removing
"type": "module"
solves the issue.🗒️ We heard the feedback and we are planning a redesign of
db seed
(currently planned to be released early September)How it will work is that a
prisma.seed
property in the package.json of your project will be required if you want to useprisma db seed
.This property is where you will be able to put any command you want to execute your seed script.
More info/details & how to try it out now in: https://github.com/prisma/prisma/issues/8732