web icon indicating copy to clipboard operation
web copied to clipboard

The script provided for db seed is not working

Open edustef opened this issue 5 years ago • 4 comments

Hello everyone, I've been trying to seed a database using prisma db seed --preview-feature. I installed ts-node and added the follow script inside package.json as described in https://www.prisma.io/docs/guides/database/seed-database#seeding-your-database-with-typescript in step 4. This was recommended because my setup uses TypeScript and NextJS.

"ts-node": "ts-node --compiler-options '{\\\"module\\\":\\\"commonjs\\\"}'"

This would throw the following error:

SyntaxError: Unexpected token ' in JSON at position 0
    at JSON.parse (<anonymous>)
    at parse (D:\Projects\logu\node_modules\ts-node\dist\util.js:48:45)
    at arg (D:\Projects\logu\node_modules\arg\index.js:122:24)
    at main (D:\Projects\logu\node_modules\ts-node\dist\bin.js:17:67)
    at Object.<anonymous> (D:\Projects\logu\node_modules\ts-node\dist\bin.js:293:5)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Error: Command failed with exit code 1: ts-node --compiler-options '{"module":"commonjs"}' "prisma\seed.ts"

What ended up working was this:

"ts-node": "ts-node --compiler-options {\"\"\"module\"\"\":\"\"\"CommonJS\"\"\"}"

Setup:

  • Windows
  • NextJS with Typescript
  • prisma and @prisma/client both on v2.24.1

edustef avatar Jun 07 '21 16:06 edustef

Thanks for raising this @edustef

molebox avatar Jun 08 '21 11:06 molebox

Hey @edustef would you be able to tell us what terminal you used on your windows machine? Thanks

molebox avatar Jun 08 '21 11:06 molebox

Hey @edustef would you be able to tell us what terminal you used on your windows machine? Thanks

I ran the command in cmd inside VSCode and also I tried in Powershell via Windows Terminal.

edustef avatar Jun 08 '21 11:06 edustef

Some context for you @edustef , the issue was with the single quotes. My bad, i added them. Its now been fixed. Thanks for reporting this.

molebox avatar Jun 08 '21 12:06 molebox