PacktPublishing / Full-Stack-Web-Development-with-Remix

Full Stack Web Development with Remix, published by Packt
MIT License
127 stars 24 forks source link

Failed to seed local database with node version >= 20 #128

Closed bpeter340 closed 9 months ago

bpeter340 commented 9 months ago

Describe the bug

BeeRich's npm run seed script fails while using node version >= 20

To Reproduce

Steps to reproduce the behavior:

  1. If using nvm, switch to node version 20 or greater
  2. Clone the repository
  3. Navigate to 05-fetching-and-mutating-data/bee-rich/start
  4. Follow the setup instructions
  5. The npm run seed script throws a TypeError

Expected behavior

Using node version 19

➜  start git:(main) node -v
v19.6.0
➜  start git:(main) npm run seed

> seed
> npx ts-node --esm prisma/seed.ts

🌱 Seeding the database...
πŸš€ Seeded the database. Done in 295ms

Actual behavior

Using node version >=20


➜  start git:(main) node -v
v20.10.0
➜  start git:(main) npm run seed

seed
npx ts-node --esm prisma/seed.ts

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/bart/Documents/Projects/Full-Stack-Web-Development-with-Remix/05-fetching-and-mutating-data/bee-rich/start/prisma/seed.ts at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9) at defaultGetFormat (node:internal/modules/esm/get_format:203:36) at defaultLoad (node:internal/modules/esm/load:141:22) at async nextLoad (node:internal/modules/esm/hooks:865:22) at async nextLoad (node:internal/modules/esm/hooks:865:22) at async Hooks.load (node:internal/modules/esm/hooks:448:20) at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18) { code: 'ERR_UNKNOWN_FILE_EXTENSION' }



**Screenshots**

Actual
![Screenshot 2023-12-12 at 12 04 30β€―AM](https://github.com/PacktPublishing/Full-Stack-Web-Development-with-Remix/assets/28541336/cfb1d0f5-d9ff-4123-9a41-ff09ad846764)

Expected
![Screenshot 2023-12-12 at 12 05 37β€―AM](https://github.com/PacktPublishing/Full-Stack-Web-Development-with-Remix/assets/28541336/8f0d4576-4c3c-42e5-a533-b009f345df00)

**Environment (if applicable):**

 - OS: M2 Mac IOS
 - Node version: >=20.10.0

**Additional context**

- Chapter: 5
- Page: 84
- Link to relevant README/code: https://github.com/PacktPublishing/Full-Stack-Web-Development-with-Remix/blob/main/05-fetching-and-mutating-data/bee-rich/start/README.md
andrelandgraf commented 9 months ago

Thank you very much for reporting. I can reproduce it on node v20. Will have a closer look later today.

andrelandgraf commented 9 months ago

This seems to be a common issue with ts-node: https://github.com/TypeStrong/ts-node/issues/1997. I replaced ts-node now with tsx: https://github.com/PacktPublishing/Full-Stack-Web-Development-with-Remix/commit/c7b0354d0e9f446a1f8e0bf37eb903eb42bba1c0. Was able to run npm run seed on both node v18 and v20 with tsx.

Let me know if that works for you!

bpeter340 commented 9 months ago

This works. Thanks!