ASAR error when used with Electron #5200
|
Hi there, Thank you so much for all the hard work that goes into a project like this. I am getting an error I have verified the I found this issue #4356 but I am not sure how I can fix this particular issue. Thank you for the help. |
Replies: 5 comments 9 replies
|
Hi @AkshayPathak! We ship the query engine binary with Studio, so I can definitely help you with this. First things first, you want to make sure that you generate Prisma Client against your schema BEFORE packaging your app. It is possible to generate Client on the fly (like we do in Studio), but that process is a lot more involved. In your case, I'm assuming you do not need to support multiple schemas, so it'll probably be easier to generate Client up front. Now that you have everything ready to be pacjaged, you should know that executables inside an ASAR archive cannot work. Normally, Once you do that, you'll have to tell Prisma Client where this query engine binary (QE for short) was relocated to. Normally, Prisma Client can automatically locate the QE, but in this specific case, since you (electron-builder) moved it out, you need to tell Client where it is. In it's constructor, you can tell Prisma Client where to locate the QE this way: let prisma = new PrismaClient({
__internal: {
engine: {
binaryPath: "/path/to/binary"
}
}
})In your case, if the QE gets unpacked by import path from 'path'
import { app } from 'electron'
const qePath = path.join(
app.getPath().replace('app.asar', 'app.asar.unpacked'),
'node_modules/@prisma/engines/query-engine-windows.exe'
)Again, you should also be able to locate it in Explorer in If you have any other questions, or need more help, let me know! |
|
I'm struggling to get this working. I fixed the same error with the suggested asarUnpack but now I get "Could not open datamodel file "C:\projects\myApp\dist\electron\Packaged\win-unpacked\resources\app.asar\schema.prisma" I didn't point it to the binary but it seems to be able to find it anyway? I tried unpacking the Schema file but the engine still looks in the same spot. There doesn't seem to be a way to point the query engine at a different schema location. Maybe I don't really understand what's happening. |
|
Hey @MitchellMonaghan, do you happen to have a repository I can look at? There's a bunch of moving pieces, so looking at code should help me figure out what's up. IIUC, you're able to package the query engine binary with your app (using the copy webpack plugin), but on launch, the query engine expects to find your schema at There are ways to override this, but they're very obscure (and very much implementation details) and may change without notice, so I'd like to make sure you avoid depending on them. One very generic solution I can give you is to try out the new Another generic (but incorrect) solution would be to place your schema in the location the query engine is looking for it in, and see if that works. If it does, we can start back-tracking. But if you give me some code, I'll be able to help you better! |
|
Hello, i have run into a similiar error after building my electron app with prisma, i am using vite and electron builder after looking up some stuff i changed my vite config
so it wouldnt exclude prisma client and that fixed some errors for me so now i "only" have this error, if anyone needs more info i can create a repo with my config files if that helps |
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |


Hi @AkshayPathak! We ship the query engine binary with Studio, so I can definitely help you with this.
First things first, you want to make sure that you generate Prisma Client against your schema BEFORE packaging your app. It is possible to generate Client on the fly (like we do in Studio), but that process is a lot more involved. In your case, I'm assuming you do not need to support multiple schemas, so it'll probably be easier to generate Client up front.
Now that you have everything ready to be pacjaged, you should know that executables inside an ASAR archive cannot work. Normally,
electron-builder(if you use it) automatically "unpacks" any executables to anapp.asar.unpackedfolder.…