nuxt: Dev server frequently freezes when using NX and Prisma

Environment

  • Operating System: Windows_NT
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0-rc.1
  • Package Manager: npm@8.3.1
  • Builder: vite
  • User Config: typescript
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/rdmchr/Rose/tree/vite

  • Clone the repo
  • Switch to the vite branch
  • Run npm i
  • Create a .env file with the following content:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
  • Run npm run dev
  • Open the index page in your browser
  • Wait ~2 minutes
  • Reload the tab

Describe the bug

After some time the Vite dev server no longer responds to requests. Requests sent to the server neither load nor time out. This affects both frontend and server URLs.

There are no errors in the vite console nor in the browser console.

Additional context

No response

Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 20 (6 by maintainers)

Most upvoted comments

I have similar issue with Nuxt 3.0.0-rc.3. Here my reproduction repo.

I Call Prisma in single server api: https://github.com/cawa-93/nuxt-prisma-hmr-issue/blob/e42d72ca6fd6226601971f6001a9342764e9f45a/server/api/users.ts

FIrst time request to /api/users return [] as expected. But after HMR server gets stuck or crashes


Operating System: `Windows 10`
Node Version: v16.14.0
Nuxt Version: 3.0.0-rc.3
Package Manager: npm@8.3.1
Builder: vite
User Config: typescript
Runtime Modules: -
Build Modules: -

Also I had to change the implementation slightly this is what my new implementation looks like.

import { PrismaClient } from '@prisma/client';

declare global {
    let prismaClient: PrismaClient | undefined;
}
let prismaClient: PrismaClient | undefined;
const prisma = prismaClient || new PrismaClient();

if (process.env.NODE_ENV !== 'production') prismaClient = prisma

export default prisma

It must come from Windows. I don’t have this problem on Linux

So switching to WSL could at least be a temporary workaround?

It must come from Windows. I don’t have this problem on Linux

Exactly the same problem, either I could not get an answer from Nitro. Or it’s prisma trying to connect to the pool and never succeeding. However when I restart Nuxt, no problem, until the hot reload. (And it depends on the time…)

I have the impression that it is related to Prisma, because if I have no connection to a db, it always works well.