You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Node hangs when console.log(new PrismaClient()) #18292
Linux - node process hangs (stuck on prisma:client:libraryEngine internalSetup +0ms)
Windows - javascript out of memory error.
Any schema.
Affected versions of @prisma/client > 4.7.0
How to reproduce
npx prisma init
npx prisma generate (npx prisma db push)
Create index.mjs with:
import { PrismaClient } from '@prisma/client'
console.log(new PrismaClient())
Reacted by Pedro Lopes, Martin Janeček, Xaliks, Stefano Sandes, João Vitor Scheuermann, tjhiggins, DreamAwakening, Ludvík Prokopec, Xegulon, drico and 3 more
The issue is in 4.8.0 and all later versions while it's not present in 4.7.0 or older versions. I believe the issue is related to this optimizations.
In this release, we have decreased the size of our engine files by an average of 50%. The size of the Query Engine used on Debian, with OpenSSL 3.0.x, for example, went from 39MB to 14MB. We will also remove some smaller engines to decrease the total size in future versions.
I've encountered this as well. I use a development repl in one of my projects, and though I can const p = new PrismaClient(), a subsequent p to check whether it's defined hangs the process.
This also means that declaring and defining in one line works:
constp=newPrismaClient()// runs successfully in a repl
But attempting to do so in two separate steps does not:
letpp=newPrismaClient()// hangs the process in a repl
When I put the output of this into a file, it is 525 MB (551.039.534 bytes) big though - so I would not be surprised if that would crash in some environments.
I experience this too. I've had to create work arounds everywhere in our application that might have client (an instance of prisma) on a class instance. Otherwise the server freezes anytime something logs out.
To fix this, anywhere recursive information is added to the object I recommend using Reflect.defineProperty so that it can be made non-enumerable, instead of simple accessor assignment.
I'm running into an issue that may be a different manifestation of this same issue. In Visual Studio Code, whenever I attempt to debug into a class that extends PrismaClient, the node process hangs. Also if I attempt to inspect the instance of this class before stepping into it, the node process hangs. I'm not able to debug any of my classes that extend PrismaClient because of this. I wonder if the debugging issue has something to do with the debugger inspecting the PrismaClient instance for a watch locals or something and this inspecting leads to the same error as logging the PrismaClient instance.
I'm also experiencing this issue after upgrading from 4.11.0 to latest 5.9.1.
When attaching the debugger to some breakpoints while working on some client extensions, it hangs the whole application (drove me crazy today, just in the middle of a deadline 🫠)
Hey everyone that commented in this issue before, could you please try to temporarily install prisma@dev and @prisma/client@dev in your project and see if this fixes the problem? #23228 should have fixed this and will be included in the next release, but of course a confirmation of it now working as intended would be nice.
Reacted by Joël Galeran, Yoann Buzenet and Ian Sebastian
@janpio I've just tested and can confirm that the dev version no-longer freezes REPL instance when the command would output anything with prisma instance on it.
With 5.10.2 it does freeze, so the fix must've addressed it correcly.
Can't wait for the release, thanks SevInf and team for the fix 🙌
Reacted by Jan Piotrowski, Yoann Buzenet, Joël Galeran and Ian Sebastian
Hi @janpio , since it looks like the actual fix in the PR is only a few lines (and the rest are tests...), would it be possible to get a backport for those of us still stuck on 4.x? The [Symbol.for...] fix a few comments up is helpful, but has to be re-applied every time I launch the REPL.
I want to add another case where this was problematic. We have a dependency injection container where we store our Prisma client for use in parts of the app that require it. Dependencies are lazily loaded, but we connect the Prisma client on app launch, so it's always loaded.
There have been moments where we need to inspect other parts of the container, so we'll console.log the container. This is probably a bad idea, but we would log out the full container to inspect it. This would unfortunately hang the entire process during development and we were never able to figure out why this was happening. So now we know!
Activity
janpio commentedon Mar 14, 2023
Why do you want to
console.log(new PrismaClient())?AvIsBeastMC commentedon Mar 19, 2023
fr
entrptaher commentedon Apr 5, 2023
I did this and then whenever I wanted to console.log(prisma) anywhere for any reason, it hung the whole process.
The issue is in 4.8.0 and all later versions while it's not present in 4.7.0 or older versions. I believe the issue is related to this optimizations.
professor-l commentedon Apr 17, 2023
I've encountered this as well. I use a development repl in one of my projects, and though I can
const p = new PrismaClient(), a subsequentpto check whether it's defined hangs the process.This also means that declaring and defining in one line works:
But attempting to do so in two separate steps does not:
[-]NodeJS hangs when console.log(new PrismaClient())[/-][+]NodeJS hangs when `console.log(new PrismaClient())`[/+][-]NodeJS hangs when `console.log(new PrismaClient())`[/-][+]Node hangs when `console.log(new PrismaClient())`[/+]janpio commentedon Apr 18, 2023
I can actually log
new PrismaClient()fine:When I put the output of this into a file, it is 525 MB (551.039.534 bytes) big though - so I would not be surprised if that would crash in some environments.
The output looks recursive to me in 2 places:
Both cases are roughly 100.000 lines long in my file.
Not optimal.
jonschlinkert commentedon Apr 21, 2023
I experience this too. I've had to create work arounds everywhere in our application that might have
client(an instance of prisma) on a class instance. Otherwise the server freezes anytime something logs out.To fix this, anywhere recursive information is added to the object I recommend using
Reflect.definePropertyso that it can be made non-enumerable, instead of simple accessor assignment.Example:
janpio commentedon May 17, 2023
This seems to also happen when logging the
txinside an interactive$transaction- which makes sense as that is just another Client instance: #19137SD-Gaming commentedon Jul 14, 2023
I have met this issue too,
23 remaining items
fix: add custom inspect to work around a Prisma issue that causes con…
fix: add custom inspect to work around a Prisma issue that causes con…
fix(client): add disable `customInspect` for `createCompositeProxy`
codeinearts commentedon Feb 2, 2024
I'm also experiencing this issue after upgrading from 4.11.0 to latest 5.9.1.
When attaching the debugger to some breakpoints while working on some client extensions, it hangs the whole application (drove me crazy today, just in the middle of a deadline 🫠)
codeinearts commentedon Feb 2, 2024
I can confirm this workaround also fixes my issue using the debugger when extending PrismaClient as a class in the context of a NestJS application
fix(client): Prevent nodejs from hanging on console.log/util.inspect …
fix(client): Prevent nodejs from hanging on console.log/util.inspect …
janpio commentedon Mar 4, 2024
Hey everyone that commented in this issue before, could you please try to temporarily install
prisma@devand@prisma/client@devin your project and see if this fixes the problem? #23228 should have fixed this and will be included in the next release, but of course a confirmation of it now working as intended would be nice.wodCZ commentedon Mar 5, 2024
@janpio I've just tested and can confirm that the
devversion no-longer freezes REPL instance when the command would output anything with prisma instance on it.With
5.10.2it does freeze, so the fix must've addressed it correcly.Can't wait for the release, thanks SevInf and team for the fix 🙌
YoannBuzenet commentedon Mar 7, 2024
It works with the dev version. Thank you !
thw0rted commentedon Apr 19, 2024
Hi @janpio , since it looks like the actual fix in the PR is only a few lines (and the rest are tests...), would it be possible to get a backport for those of us still stuck on 4.x? The
[Symbol.for...]fix a few comments up is helpful, but has to be re-applied every time I launch the REPL.janpio commentedon Apr 19, 2024
Unfortunately not, we never maintain older versions by backporting changes or fixes.
You would need to do that yourself in a fork and publish it under your own package name.
Probably you can achieve something similar using https://www.npmjs.com/package/patch-package
divmgl commentedon May 13, 2024
Thanks for this fix.
I want to add another case where this was problematic. We have a dependency injection container where we store our Prisma client for use in parts of the app that require it. Dependencies are lazily loaded, but we connect the Prisma client on app launch, so it's always loaded.
There have been moments where we need to inspect other parts of the container, so we'll
console.logthe container. This is probably a bad idea, but we would log out the full container to inspect it. This would unfortunately hang the entire process during development and we were never able to figure out why this was happening. So now we know!So thank you for fixing this bug! Super helpful!