saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.88k stars 223 forks source link

prisma and nextron: Error: Cannot find module '.prisma/client/index #386

Open iarlen-reis opened 1 year ago

iarlen-reis commented 1 year ago

I recently tried to implement prisma with sqlite in my project with nextron, but unfortunately I encountered some problems. in development, the prisma connection with sqlite works normally, but when generating an application build and trying to run it, this error occurred:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module '.prisma/client/index'
Require stack:
- /snap/manager-testing/x3/resources/app.asar/node_modules/@prisma/client/index.js
- /snap/manager-testing/x3/resources/app.asar/app/background.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at n._resolveFilename (node:electron/js2c/browser_init:249:1105)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at c._load (node:electron/js2c/asar_bundle:5:13343)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/snap/manager-testing/x3/resources/app.asar/node_modules/@prisma/client/index.js:2:6)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1175:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
Gtk-Message: 15:52:41.381: Failed to load module "xapp-gtk3-module"

by the looks of it, nextron can't find @prisma/client when trying to run it, I tried some solutions I found on the internet, like copying the prisma folder into ./dist after the build, but that didn't work either.

would anyone have a solution for this problem? maybe an example explaining how to implement prism with nextron.

implementation attempt repository: github repository

other information:

"electron": "^21.3.3",
"electron-builder": "^23.6.0",
"next": "^12.3.4",
"nextron": "^8.5.0",
"prisma": "^5.0.0",
ekeyur commented 1 year ago

Hi, Did you ever solve this problem?

makeusabrew commented 1 year ago

This isn't a complete solution by any means; I've only just started using both Nextron and Prisma so there are probably lots more bumps to come, but adding the following to my electron-builder.yml as a top-level property (not nested within files or anything) allows my app to boot successfully:

extraResources:
  - node_modules/.prisma/**/*
  - node_modules/@prisma/client/runtime/**/*

Pretty sure this is only the tip of the iceberg, and depending on how your app is structured the next problem you might hit is that Prisma can't find your sqlite database - but that's a userland/runtime issue you can solve in lots of different ways (as are things like migrations - I expect they'll be fun too).