skip to Main Content

I am using Prisma (sqlite DB) with an Electron + Angular app

Everything works fine until I try to create a record

I’m getting this error in console few times repeated

Here is a part of my schema.prisma file:

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

generator client {
    provider = "prisma-client-js"
    binaryTargets = ["native","darwin","debian-openssl-1.1.x","linux-musl"]
  }

I’ve tried using the same Prisma config with a scratch TS project and it works fine

When I’ve tried it with electron I was getting errors

As I understand it cannot find query engine binaries, but I don’t know how to say to Electron where to get them from

2

Answers


  1. Hi

    I too had similar problem with prisma.

    1. The issue is that the custom prisma client along with the downloaded binaries for the platform of use gets generated in node_modules/.prisma folder (default).

    2. when webpack bundled the code, .prisma folder wasn’t included with the generated app.asar package in node_modules folder and thus prisma client couldn’t be loaded along with the binaries.

    Solution

    I changed the output path of the generated prisma client as per prisma doc

    generator client {
      provider = "prisma-client-js"
      output   = "../src/main/database/generated/client"
    }
    

    and included in my database.js file (located inside database folder) as follows

    import { PrismaClient } from './generated/client';
    

    As the downloaded binaries are also placed indside the output folder, there was no problem for prisma client in finding it.

    Login or Signup to reply.
  2. I had the same issue when using electron-builder to build native binaries.
    In my case I had to add .env file to the build block on package.json and change the output path as spc mentioned.

    // package.json
    {
     ...
      "build": {
        ...
        "files": [
          ...
          ".env"
        ],
        ...
      }
    }
    
    // schema.prisma
    generator client {
      provider = "prisma-client-js"
      output   = "../electron/client"
      binaryTargets = ["native"]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search