Closed x15sr71 closed 2 weeks ago
@VineeTagarwaL-code I would like to raise a PR to fix this issue; please assign it to me
There's not a kind of fix issue for this...
Before making the change seed script was this:
"prisma": { "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" },
and it was also raising this issue
After making the change:
"prisma": { "seed": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' prisma/seed.ts" },
both seeding scripts were failing on my side
so i had to think of alternate solution that was to use
tsx
instead of ts-node
"prisma: :{ "seed":"tsx prisma/seed.ts" }
Not sure if it works on your end
Thanks for the insights, @CuriousCoder00!
I found that the issue arises from the use of the --import flag in the seeding script. After some investigation, the ERR_MODULE_NOT_FOUND occurs because the --import flag isnβt properly supported in this context.
To fix this, I will switch to using the --loader flag in the scripts section of the package.json as it provides a more stable and expected behavior with ES module loading.
I have tested it, and it works on my end.
Final script would look something like following in the scripts in package.json:
"scripts": { "db:seed": "npx prisma db push && node --loader ts-node/esm prisma/seed.ts" }
so is it open or solved?
@NalinDalal i raised pr which solves the issue, but isn't merged yet
nice work, make sure you post on x about your pr merge happy coding :rocket:
π Description
When attempting to run the database seed script using the command: npm run db:seed
π Reproduction steps
π Expected behavior
The database seed script should run without any errors, and the data should be seeded successfully.
π Actual Behavior with Screenshots
An ERR_MODULE_NOT_FOUND error is thrown, indicating that the package cannot be found.
OS name
Windows
browser name
Firefox
npm version
No response
node version
No response
π Provide any additional context for the Bug.
The issue seems to stem from the way the --import flag is used in the command. The command that causes the error: node --import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));' prisma/seed.ts
possible fix would be to use the --loader option instead of --import.
π Have you spent some time to check if this bug has been raised before?
π’ Have you read the Contributing Guidelines?
Are you willing to submit PR?
Yes I am willing to submit a PR!