superbunches
03/28/2022, 4:34 PMlocalhost:3000
was causing PrismaClient and my project to be out of sync.
I’ll do my best to describe what happened in a thread 👇superbunches
03/28/2022, 4:34 PMnpm run dev
, and my app is served at localhost:3000
superbunches
03/28/2022, 4:35 PMModel
(User, since I’m adding auth). I set up my endpoint, which calls prisma.user.create({ … })
Immediately, I was getting the error:
Cannot read properties of undefined (reading 'create')
TypeError: Cannot read properties of undefined (reading 'create')
at Module.api (/Users/.../Projects/.../src/routes/users/_api.ts:24:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async render_endpoint (file:///Users/.../Projects/.../.svelte-kit/runtime/server/index.js:157:19)
superbunches
03/28/2022, 4:35 PMprisma
and user
in prisma.user.create()
, and seeing the associated data and methods (see https://imgur.com/a/zkXkc8d and https://imgur.com/a/dDQ0XEF). I was also able to run npx prisma studio
, and my new User
model was there.superbunches
03/28/2022, 4:35 PMCannot read properties of undefined (reading 'create')
extra confusing, since all evidence pointed to Prisma having generated my update to the schema successfully, and furthermore, after migrating, Postgres indeed had my new User
table.superbunches
03/28/2022, 4:35 PMgenerate
and migrate
commands, along with trying prisma migrate reset
. I also rolled back to older migrations, completely removed the /prisma directory and did a re-init. I created and connected a new Postgres db, which only ended up in the same dead ends (User
model seemed to exist everywhere in my project and db, but I was getting the same error about the .create()
function). In desperation, I tried older versions of the Prisma and PrismaClient packages, and also completely uninstalling and re-installing Postgres on my machine.superbunches
03/28/2022, 4:36 PMtoo many clients
issue brewing, I updated to this approach, but my error was still persisting. At this point in time, I don’t know if this was the cause of the breakdown in generating the PrismaClient, or the other issue I’m about to describe.superbunches
03/28/2022, 4:36 PMlocalhost:3000
was continuing to run even after I had hit Ctrl + C to stop npm run dev
. This was odd because about a week ago, when I would stop the server with Ctrl + C, the dev tools console would immediately throw errors and page would be dead. Now all of a sudden it wasn’t.superbunches
03/28/2022, 4:36 PMnpm run dev
, ran prisma generate
and prisma migrate dev
(which told me Already in sync, no schema change or pending migration was found
) and yup, my endpoint with prisma.user.create()
is now working as expected!superbunches
03/28/2022, 4:37 PMtoo many clients
be the cause of this issue?
• Putting aside my wanting to know how npm run dev
was not being stopped, would the server not restarting have caused a previously configured PrismaClient to be accessing an old generated version of the schema, even though Prisma Studio at localhost:5555
was showing me my updated schema?
• The Cannot read properties of undefined (reading 'create')
error did not tell me much about the issue that I assume I was actually dealing with (as far as I know). If one of the two above bullet points was the cause of this issue, is there a better error that could be thrown somewhere else along the chain that could clue a developer in on what was happening?superbunches
03/28/2022, 4:37 PMjanpio
• WouldNo, that just indicates you are starting to many Prisma Client and its Query Engines internally, which is bad for memory and CPU usage and your database if you keep it up without wanting to do that - hence the error message. When you fixed that code, the restart of your app would have killed all the running Query Engines as well.be the cause of this issue?too many clients
• Putting aside my wanting to know howThat sounds indeed reasonable. That old application instance probably had older code loaded, and just kept service that. Because of hot reloading, that might have only been true for part of the code even (and it sounds to me like you had an old Prisma Client (withoutwas not being stopped, would the server not restarting have caused a previously configured PrismaClient to be accessing an old generated version of the schema, even though Prisma Studio atnpm run dev
was showing me my updated schema?localhost:5555
User
), but new code (which tries to access user
.)
• TheDo you think this waserror did not tell me much about the issue that I assume I was actually dealing with (as far as I know). If one of the two above bullet points was the cause of this issue, is there a better error that could be thrown somewhere else along the chain that could clue a developer in on what was happening?Cannot read properties of undefined (reading 'create')
prisma.user
being undefined
and then you calling create
on that? I think this would be a bit like you trying to access a model that does not exist. Would that return something different? (It would probably fail during TS type checks already in the default case) Maybe try that in your setup to see how that would go.janpio
npm run dev
. I would have expected that to use a different prot than 3000 or fail with "port already in use" in most frameworks. Is that not the case for SvelteKit?superbunches
03/29/2022, 6:10 PMpackage.json
is pretty boilerplate.superbunches
03/29/2022, 6:12 PMsuperbunches
03/29/2022, 6:14 PMprisma.user
was recognized and even provided the example findMany()
function (see screenshot above). Which is what made this extra confusingjanpio