7

I'm making a project using Electron and Prisma (along with others that we don't have to worry about). I've been trying to solve this error for hours: I can't get Prisma to find the query-engine executable, and I've tried a bunch of things I found on internet, but still nothing.

I tryed to set where Prisma will find the query-engine, this repo i found the "solution", but it did not work (at least not for me):

This is my Prisma schema:

datasource db {
    provider = "sqlite"
    url      = "file:./data.db"
}

generator client {
    provider = "prisma-client-js"
    binaryTargets = ["native"]
    output   = "../electron/database/generated/client"
}

I am using webpack to compile both Electron and React, so I set the schema generate to the Electron folder that webpack will then compile to the "dist" folder. I used the copy-webpack-plugin to copy both schema.prisma and the query-engine-windows.exe (which is my OS). After all that I get this error:

r [PrismaClientKnownRequestError]: spawn C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar.unpacked\dist\query-engine-windows.exe ENOENT
    at C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar\dist\main.js:69:77852
    at c (C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar\dist\main.js:1:54711)
    at Generator._invoke (C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar\dist\main.js:1:54464)
    at Generator.throw (C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar\dist\main.js:1:55070)
    at asyncGeneratorStep (C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar\dist\main.js:1:195068)
    at s (C:\Users\Tiago Oliveira\programming\web-dev\electron-prisma-react-ts-passwordkeeper\packages\win-unpacked\resources\app.asar\dist\main.js:1:195340)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'ENOENT',
  clientVersion: '2.24.1',
  meta: undefined
}

event using this setup to get the app path and setting the path exactly where the qe (query-engine) is it says its not there...?

import { app } from "electron"
import path from "path"
const qePath = path.join(
    app.getAppPath().replace("app.asar", "app.asar.unpacked"),
    "dist/query-engine-windows.exe"
)

const prisma = new PrismaClient(process.env.NODE_ENV === "production" ? {
    __internal: {
        engine: {
            binaryPath: qePath
        }
    }
} : {})

And to make sure I wasn't crazy, I took the path it said wasn't there and threw it to the console and it ran! So something is wrong here.

If you have any questions about how the files look, you can check at this project repo.

If you want to get the error and try out yourself to get the error, just clone the repo and do yarn and run "yarn package:exe"m, which will compile the main folder which is Electron, and then the src folder which is React, and right after that it will bundle it for Electron and then execute it right away: yarn package:exe will webpack-(all)>electron->execute.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Tiago Oliveira
  • 47
  • 1
  • 12

1 Answers1

-3

I've never worked with prisma or electron, but based on my webpack experience there are few things that sound very off:

  • webpack is good at pulling js together and outputting some other file. Forcing it to copy-paste files along feels a bit like code smell - webpack doesn't understand exe files, so most likely it shouldn't manage them
  • "schema.prisma" seems like something that is being used by js - I'm surprised it's not imported form the place it needs it
  • exe files are specific for the operating system - I would expect js build to be platform independent, and on top of that something that takes build code & wraps it with execution file

In general, I would expect quite a bit different architecture; but I cannot tell what is typically done in electron community.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Marcin Wosinek
  • 793
  • 3
  • 8
  • So if u dont know, electron is used to build native desktop apps and it can render html and a lot of front end (if not all) frameworks. Prisma is just a type-orm like datase manager and it needs that .prisma file on the directory to be used and it needs the executable too and as i was testing and i just wanted to make sure that it would work on prod i just went with windows and after i know how to do it i would eventually add other platforms too. – Tiago Oliveira Jun 30 '21 at 20:44