-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node hangs when console.log(new PrismaClient())
#18292
Comments
Why do you want to |
fr |
I did this and then whenever I wanted to console.log(prisma) anywhere for any reason, it hung the whole process. import { PrismaClient } from "@prisma/client";
let prisma = new PrismaClient();
console.log(prisma) 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.
|
I've encountered this as well. I use a development repl in one of my projects, and though I can This also means that declaring and defining in one line works: const p = new PrismaClient() // runs successfully in a repl But attempting to do so in two separate steps does not: let p
p = new PrismaClient() // hangs the process in a repl |
console.log(new PrismaClient())
console.log(new PrismaClient())
console.log(new PrismaClient())
I can actually log
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. |
I experience this too. I've had to create work arounds everywhere in our application that might have To fix this, anywhere recursive information is added to the object I recommend using Example: Reflect.defineProperty(prisma, Symbol(), {
value: {...},
enumerable: false
}); |
This seems to also happen when logging the |
I have met this issue too,
|
+1 node 20.5.1 const { PrismaClient } = require("@prisma/client");
const client = new PrismaClient();
console.log(client); |
Duplicate: #19648 |
Also reproduced in #19648 (comment), for me it was 152 MiB of output on Prisma 4.15.0 and the process hanging indefinitely on Prisma 5.2.0-dev. Analysis: #19648 (comment) |
Can you also confirm that it used to work fine in Prisma 4.7.0 and older @Druue? |
This is the behaviour that I see on Screen.Recording.2023-08-23.at.16.42.22.mov |
It's art 🤣 |
this stumped me for 2 days - why does it happen? |
This issue prevents me from using prisma in the node REPL; I don't literally want to log the output of the client, but I do want to use it in a repl. Here's a node REPL script that reproduces the issue:
run that script, type |
@llimllib you can work around the issue with this: const repl = require("node:repl");
const r = repl.start("> ");
r.context.prisma = new (require("@prisma/client").PrismaClient)();
r.context.prisma[Symbol.for('nodejs.util.inspect.custom')] = 'PrismaClient'; as suggested here: #19648 (comment) |
…sole to hang (#9623) The related Prisma issue: prisma/prisma#18292 It basically causes all kinds of Node REPLs that use PrismaClient to hang when users type the variable name that holds the client. Adding a workaround as suggested in the Prisma thread. Fixes #8817
…sole to hang (#9623) The related Prisma issue: prisma/prisma#18292 It basically causes all kinds of Node REPLs that use PrismaClient to hang when users type the variable name that holds the client. Adding a workaround as suggested in the Prisma thread. Fixes #8817
Related to #18292 This was in my stash from a recent train ride 🚋 When trying it in the `./sandbox` directory, `console.log(prisma)` works.
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 🫠) |
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 @Injectable()
export class PrismaService
extends PrismaClient<PrismaClientOptions, "query" | "error">
implements OnModuleInit, OnModuleDestroy
{
private readonly logger = new Logger(PrismaService.name);
constructor(private readonly configService: ApiConfigService) {
super({
log: [
{
emit: "event",
level: "query",
},
{
emit: "event",
level: "error",
},
{
emit: "stdout",
level: "info",
},
{
emit: "stdout",
level: "warn",
},
],
});
/**
* new PrismaClient versions hangs debugger
* https://github.com/prisma/prisma/issues/18292#issuecomment-1749123704
*/
Object.assign(this, {
[Symbol.for("nodejs.util.inspect.custom")]: "PrismaCLient",
});
this.$on("error", (event) => {
this.logger.log(event.target);
});
this.$on<any>("query", (event: Prisma.QueryEvent) => {
const { query, timestamp, duration } = event;
const collection = query.split("(")[0];
this.logger.log(
{ collection, timestamp, duration, query },
"PRISMA QUERY DEBUG"
);
});
this.$use(async (params, next) => {
const before = Date.now();
const result = await next(params);
const after = Date.now();
const duration = after - before;
this.logger.log(
{ collection: params.model, operation: params.action, duration },
`Query ${params.model}.${params.action} took ${duration} ms`
);
return result;
});
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
} |
Hey everyone that commented in this issue before, could you please try to temporarily install |
@janpio I've just tested and can confirm that the With Can't wait for the release, thanks SevInf and team for the fix 🙌 |
It works with the dev version. Thank you ! |
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 |
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. |
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 So thank you for fixing this bug! Super helpful! |
Bug description
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
export DEBUG="*" && node index.mjs
-> See errorExpected behavior
No response
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: