question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ts-node-dev hangs when creating PrismaClient

See original GitHub issue

Bug description

When I construct a PrismaClient at the top level of my express server:

const prisma = new PrismaClient();

My server no longer restarts running under ts-node-dev when source files change. And if I try to manually kill the process via a SIGTERM, the process hangs.

I’ve confirmed the issue is caused by some interaction of ts-node-dev and PrismaClient, because when I run the same server with ts-node, I can kill the process just fine.

How to reproduce

Run a long-running server with a PrismaClient under ts-node-dev

Expected behavior

No response

Prisma information

N/A

Environment & setup

  • OS: Ubuntu
  • Database: PostgreSQL, but my DATABASE_URL is empty when observing this bug
  • Node.js version: 10.19.0

Prisma Version

Environment variables loaded from .env
prisma               : 2.21.2
@prisma/client       : 2.21.2
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : e421996c87d5f3c8f7eeadd502d4ad402c89464d
Studio               : 0.371.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
mgummeltcommented, May 20, 2021

@Sytten

Adding --exit-child does in fact work. Thank you!

I don’t understand why it works, unless prisma is somehow blocking SIGTERM, and this option overrides that.

I’m happy to switch to a more reliable solution than ts-node-dev if you have any suggestions. By accounts I’ve read, nodemon is too slow, since it recompiles the entire typescript project.

2reactions
pantharshit00commented, Jul 18, 2021

@nghiepit I disagree, that is how it is implemented in ts-node-dev and I don’t think we can change anything to change the behaviour here.

Alternatively, try using the Node-API preview which doesn’t spawn a child process preventing this altogether: https://www.prisma.io/docs/concepts/components/prisma-engines/query-engine#enable-the-node-api-n-api-preview

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error importing PrismaClient in code compiled from typescript ...
And this code works after building with tsc and running the resulting code. But now running the typescript files with ts-node-dev throws this ......
Read more >
Prisma 3.14 -> 3.15 node crash - Reddit
Trying to upgrade my Node MySQL app from 3.14 to 3.15. I use prisma and prisma/client. After upgrading my node app just crashes...
Read more >
Prisma | Next-generation ORM for Node.js & TypeScript
Prisma is a next-generation Node.js and TypeScript ORM for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB, and CockroachDB. It provides type-safety, ...
Read more >
Prisma ORM Tutorial for Beginners - YouTube
I show how to make a CRUD, add many rows at the same time, ... Tags: - ReactJS Tutorial - ReactJS and MySQL...
Read more >
ts-node-dev - npm
Compiles your TS app and restarts when files are modified.. Latest version: 2.0.0, last published: 7 months ago. Start using ts-node-dev in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found