question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prisma db seed doesn't correctly support `"type": "module"`

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ymzuikucommented, May 31, 2021

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

npm i esbuild --save-dev

2 - Add seed in your package.json scripts:

"scripts": {
  "seed":"esbuild prisma/seed.ts --outfile=node_modules/tmp-seed.cjs --bundle --format=cjs --external:prisma --external:@prisma/client && node node_modules/tmp-seed.cjs --preview-feature"
}

3 - Run seed script

npm run seed

It works in my project, hope you can run it.

1reaction
Jolg42commented, Aug 13, 2021

🗒️ 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 use prisma 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma db seed & typescript problem with import and type ...
Try and double-check your seed command in the prisma section of your package.json, it should look like the one in the repo of...
Read more >
Seeding your database - Prisma
This guide describes how to seed your database using Prisma Client and Prisma's integrated seeding functionality. Seeding allows you to consistently ...
Read more >
Prisma | NestJS - A progressive Node.js framework
Prisma currently supports PostgreSQL, MySQL, SQL Server, SQLite, ... a sample NestJS application with a REST API that can read and write data...
Read more >
Hey all I m having issues with seeding data with Prisma and
Hey all I m having issues with seeding data with Prisma and ... I was also hopeful module type overrides would help, but...
Read more >
How to Get Started with Prisma ORM for Node.js and ...
js framework and PostgreSQL database. We will build a simple Quotes REST API to add and serve up programming-related quotes. Let's get started!...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found