Unable to run the seed script successfully

The seed script
import { db } from '@/app/lib/database';
import * as data from '@/app/lib/placeholder-data';

async function main() {
for (const c of data.customers) {
await db.customer.create({ data: c });
}
for (const i of data.invoices) {
await db.invoice.create({ data: i });
}
for (const r of data.revenue) {
await db.revenue.create({ data: r });
}
for (const u of data.users) {
await db.user.create({ data: u });
}
}
main();
console.log('the database has seeded successfully');
import { db } from '@/app/lib/database';
import * as data from '@/app/lib/placeholder-data';

async function main() {
for (const c of data.customers) {
await db.customer.create({ data: c });
}
for (const i of data.invoices) {
await db.invoice.create({ data: i });
}
for (const r of data.revenue) {
await db.revenue.create({ data: r });
}
for (const u of data.users) {
await db.user.create({ data: u });
}
}
main();
console.log('the database has seeded successfully');
the package.json seed script
"seed": "ts-node prisma/seed.ts"
"seed": "ts-node prisma/seed.ts"
2 Replies
Anas Badran
Anas Badran6mo ago
The error
 dashboard  pn run seed

> @ seed D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard
> ts-node prisma/seed.ts

(node:28944) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\prisma\seed.ts:1
import { db } from '@/app/lib/database';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:128:18)
at wrapSafe (node:internal/modules/cjs/loader:1280:20)
at Module._compile (node:internal/modules/cjs/loader:1332:27)
at Module.m._compile (D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\node_modules\.pnpm\[email protected]_@[email protected][email protected]\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Object.require.extensions.<computed> [as .ts] (D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\node_modules\.pnpm\[email protected]_@[email protected][email protected]\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Function.Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at phase4 (D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\node_modules\.pnpm\[email protected]_@[email protected][email protected]\node_modules\ts-node\src\bin.ts:649:14)
 ELIFECYCLE  Command failed with exit code 1.
 dashboard  pn run seed

> @ seed D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard
> ts-node prisma/seed.ts

(node:28944) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\prisma\seed.ts:1
import { db } from '@/app/lib/database';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:128:18)
at wrapSafe (node:internal/modules/cjs/loader:1280:20)
at Module._compile (node:internal/modules/cjs/loader:1332:27)
at Module.m._compile (D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\node_modules\.pnpm\[email protected]_@[email protected][email protected]\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Object.require.extensions.<computed> [as .ts] (D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\node_modules\.pnpm\[email protected]_@[email protected][email protected]\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Function.Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at phase4 (D:\coding\evolving\JavaScript\next\nextjs-dashboard\dashboard\node_modules\.pnpm\[email protected]_@[email protected][email protected]\node_modules\ts-node\src\bin.ts:649:14)
 ELIFECYCLE  Command failed with exit code 1.
I also tried to change the seed script:
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts",
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts",
it also didn't work
Nurul
Nurul6mo ago
Hey @AnsBdran 👋 Can you please add type:"module" to your package.json and check?
{
"type": "module",
"scripts": {
"seed": "ts-node prisma/seed.ts"
},
...
}
{
"type": "module",
"scripts": {
"seed": "ts-node prisma/seed.ts"
},
...
}
Alternatively you can also try replacing your import statement with require
Want results from more Discord servers?
Add your server