epicweb-dev / data-modeling

Model and query your data with confidence
https://www.epicweb.dev
Other
151 stars 61 forks source link

Persistent error in 1:1 relationships problem #42

Closed kdaviduik closed 7 months ago

kdaviduik commented 7 months ago

While following the steps in this problem, whenever I run npx tsx ./prisma/seed.ts I get this error:

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
TypeError [Error]: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at bt (file:///Users/karadaviduik/Documents/data-modeling/node_modules/tsx/dist/index-bd1ceb03.mjs:16:1598)
    at file:///Users/karadaviduik/Documents/data-modeling/node_modules/tsx/dist/index-bd1ceb03.mjs:17:635
    at hr (file:///Users/karadaviduik/Documents/data-modeling/node_modules/tsx/dist/index-bd1ceb03.mjs:16:1071)
    at Cr (file:///Users/karadaviduik/Documents/data-modeling/node_modules/tsx/dist/index-bd1ceb03.mjs:17:563)
    at Z (file:///Users/karadaviduik/Documents/data-modeling/node_modules/tsx/dist/esm/index.mjs:5:1787)
    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)

Node.js v20.10.0

I have pulled the latest changes for this repo and restarted everything, and my database consists of a note and a user (as set up in the previous exercises).

kentcdodds commented 7 months ago

Try deleting the playground directory and setting it over again.

I'm afraid this workshop is tricky with all the database changes

kdaviduik commented 7 months ago

Thank you! I just tried that and got the same error. I then tried using the schema.prisma and seed.ts from the solution diff, same error.

Both of these files are within the prisma directory:

schema.prisma ``` // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { provider = "prisma-client-js" } datasource db { provider = "sqlite" url = env("DATABASE_URL") } model User { id String @id @default(cuid()) email String @unique username String @unique name String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt image UserImage? notes Note[] } model Note { id String @id @default(cuid()) title String content String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade, onUpdate: Cascade) ownerId String images NoteImage[] } model NoteImage { id String @id @default(cuid()) altText String? contentType String blob Bytes createdAt DateTime @default(now()) updatedAt DateTime @updatedAt note Note @relation(fields: [noteId], references: [id], onDelete: Cascade, onUpdate: Cascade) noteId String } model UserImage { id String @id @default(cuid()) altText String? contentType String blob Bytes createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade) userId String @unique } ```
seed.ts ``` import { PrismaClient } from '@prisma/client' import fs from 'node:fs' const prisma = new PrismaClient() const firstNote = await prisma.note.findFirst() if (!firstNote) { throw new Error('You need to have a note in the database first') } await prisma.note.update({ where: { id: firstNote.id }, data: { images: { create: [ { altText: 'an adorable koala cartoon illustration', contentType: 'image/png', blob: await fs.promises.readFile( './tests/fixtures/images/kody-notes/cute-koala.png', ), }, { altText: 'a cartoon illustration of a koala in a tree eating', contentType: 'image/png', blob: await fs.promises.readFile( './tests/fixtures/images/kody-notes/koala-eating.png', ), }, ], }, }, }) ```

I am running npx prisma db push (which succeeds) followed by npx tsx ./prisma/seed.ts

kentcdodds commented 7 months ago

Hi @kdaviduik!

I'm sorry you're having this trouble. I just tried it myself and did not have any errors.

From the look of the error, it's actually coming from tsx which is basically like running node, but it supports running ts files. So it seems there may be some issue with your version of node or your system when you run that package. I dove into the spot where that error is happening and it's on this statement: const[e]=n.errors;

So my guess is there was some kind of error, and when tsx was trying to give you a friendly error message it failed because n.errors (whatever that is) is undefined and therefore can't be destructured.

If you're feeling brave, you could go into that file at that location and add console.log(errors); right before const[e]=n.errors; and maybe that'll give you more information.

Alternatively, you could just change the file from seed.ts to seed.js for this exercise and run that with node.

Unfortunately I'm guessing you'll have the same problem any time you want to run the seed script and I do think there will be some typescript syntax in future exercises.

If you'd like to come to my office hours sometime, then we can pair on it together to figure out what's going on. Otherwise, I'm afraid there's not much more I can do to help you troubleshoot what's going on with your setup. Sorry!