mysqlnode.jsexpressprismaeconnrefused

Prisma ECONNREFUSED error after running prisma migrate / generate


I have a Prisma client connected to a local MySQL database inside of an express server. The server and database work fine at first and the typings are also correct. But:

After running npx prisma migrate dev or npx prisma generate, nothing works anymore.

It always throws connect ECONNREFUSED ::1:50898 when performing any request

The only workaround that kind of works is creating the same exact schema again, but on another node project, doing prisma generate and then copying the generated ".prisma" folder inside of my node_modules.

The error comes up on my localhost MySQL DB, but also when connected to a PrismaCloud Postgres DB.

It is really annoying to me because I really likee Prisma, but with this issue I can't really use it productively.

I am using a global prisma client for my server like this:

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

const prisma = new PrismaClient();

export default prisma;

My schema under ./prisma/schema.prisma looks like this:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model User {
  id           Int        @id @default(autoincrement())
  email        String     @unique
  password     String
}

my DATABASE_URL looks like this: DATABASE_URL="mysql://root:password@127.0.0.1:3306/merkurier?schema=public"

and an example of a failing query looks like this:

 const user = await prisma.user.findFirst({
            where: {
              email,
            },
          });

I am using an M1 mac and not using docker (maybe I should use Docker)


Solution

  • Prisma runs natively on the Apple M chips and there's nothing to configure, but I had the same issue, Prisma error: connect ECONNREFUSED ::1:50269, I realized that this problem can have different causes like unsupported Node.js engine on your machine, Prisma under 3.x or query engine not reachable on your host
    In my case, my issue resolved after install latest Prisma manually.
    For installing the latest Prisma following command:

    npm i --save-dev prisma@latest
    npm i @prisma/client@latest