Can't seed database in Next.js and TS project
See original GitHub issueBug description
Can’t seed a database inside a Next.js with TypeScript project.
Seed script in package.json
copied from the docs, give the following error:
"prisma": {
"seed": "ts-node --compiler-options \"{\\\"module\\\":\\\"CommonJS\\\"}\" prisma/seed.ts"
},
Error:
An error occured while running the seed command:
/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:692
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
error TS5023: Unknown compiler option '0'.
error TS5023: Unknown compiler option '1'.
error TS5023: Unknown compiler option '2'.
error TS5023: Unknown compiler option '3'.
error TS5023: Unknown compiler option '4'.
error TS5023: Unknown compiler option '5'.
error TS5023: Unknown compiler option '6'.
error TS5023: Unknown compiler option '7'.
error TS5023: Unknown compiler option '8'.
error TS5023: Unknown compiler option '9'.
error TS5023: Unknown compiler option '10'.
error TS5023: Unknown compiler option '11'.
error TS5023: Unknown compiler option '12'.
error TS5023: Unknown compiler option '13'.
error TS5023: Unknown compiler option '14'.
error TS5023: Unknown compiler option '15'.
error TS5023: Unknown compiler option '16'.
error TS5023: Unknown compiler option '17'.
error TS5023: Unknown compiler option '18'.
error TS5023: Unknown compiler option '19'.
error TS5023: Unknown compiler option '20'.
at createTSError (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:692:12)
at reportTSError (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:696:19)
at create (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:707:36)
at Object.register (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:485:19)
at main (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/bin.ts:249:19)
at Object.<anonymous> (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/bin.ts:482:3)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12) {
diagnosticText: "\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '0'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '1'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '2'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '3'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '4'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '5'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '6'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '7'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '8'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '9'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '10'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '11'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '12'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '13'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '14'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '15'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '16'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '17'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '18'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '19'.\n" +
"\x1B[91merror\x1B[0m\x1B[90m TS5023: \x1B[0mUnknown compiler option '20'.\n",
diagnosticCodes: [
5023, 5023, 5023, 5023,
5023, 5023, 5023, 5023,
5023, 5023, 5023, 5023,
5023, 5023, 5023, 5023,
5023, 5023, 5023, 5023,
5023
]
}
Updating the script to this however, gives a different (but clearer) error:
"prisma": {
"seed": "ts-node prisma/seed.ts --compiler-options '{\"module\":\"CommonJS\"}'"
},
Error:
import { PrismaClient } from '@prisma/client';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:988:16)
at Module._compile (internal/modules/cjs/loader.js:1036:27)
at Module.m._compile (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:1310:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Object.require.extensions.<computed> [as .ts] (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/index.ts:1313:12)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at main (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/bin.ts:331:12)
at Object.<anonymous> (/Users/m-abdelwahab/Desktop/next-prisma-3/node_modules/ts-node/src/bin.ts:482:3)
Updating the module
value to CommonJS
in the tsconfig.json file fixes it. Is this a good solution? What are the downsides of doing this. I saw a solution where one can create another tsconfig.json
file with different settings and use that with ts-node but it seems overkill
How to reproduce
Clone this example repo and try running npx prisma db seed
Expected behavior
It should seed the database.
Prisma information
Example repo above
Environment & setup
- OS: MacOS
- Database: tried PostgreSQL and SQLite
- Node.js version: v14.17.4
Prisma Version
prisma : 3.0.2
@prisma/client : 3.0.2
Current platform : darwin
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio : 0.423.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >How to seed a database with Prisma and Next.js - PlanetScale
In this tutorial, we'll see how to seed a PlanetScale database using Prisma in a Next.js project. Check out the Prisma quickstart for...
Read more >Preview feature feedback: Integrated seeding #5161 - GitHub
I'm using next.js and trying to seed, when I run the commend it doesn't work. But every time I start next.js it seeds...
Read more >Seeding your database - Prisma
Seeding your database with TypeScript or JavaScript · Create a new file named seed.ts . This can be placed anywhere within your projects...
Read more >Going to Production - Next.js
Ensure your database and backend are deployed in the same region. ... next start in order to prevent accidental caching of responses that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try replace it with:
Thank you very much @m-abdelwahab for reporting the issue and @kurniawanw0194 for the solution! You saved my time.
@pantharshit00 Is it possible to add this solution to the Prisma 3 documentation? Thanks