Skip to content Skip to sidebar Skip to footer

Electron-prisma Error: Can Not Find Module '.prisma/client'

I'm building a Nuxt-electron-prisma app and I kinda stuck here. when I use prisma normally as guided every thing is fine on dev but on build i get this error : A javascript error o

Solution 1:

The solution provided by Mojtaba Barari works but it results in @prisma packages being present in both resources/app/node_modules and resources/node_modules.

There is a better way how to do it:

{"build":{"extraResources":[{"from":"node_modules/.prisma/client/","to":"app/node_modules/.prisma/client/"}],}}

In this case, the Prisma client files will be copied directly to resources/app/node_modules where other @prisma packages are already present and so you will save ~ 10 MB compared to the other solution.

EDIT:

My previous solution doesn't work if an application is packaged into an asar archive. You need to use files field instead:

{"build":{"files":[{"from":"node_modules/.prisma/client/","to":"node_modules/.prisma/client/"}],}}

This is a universal solution which works even if you don't use an asar archive.

Solution 2:

Ok, I finally solved it!! first of all no need to change client generator output direction!

//schema.prisma
datasource db {
  provider = "sqlite"
  url      = "file:../resources/database.db"
}
generator client {
  provider = "prisma-client-js"// output   = "../resources/prisma/client"  !! no need for this!
}

then in electron-builder config add ./prisma , @prisma and database

// my config file was a .ymlextraResources:
  - "resources/database.db"
  - "node_modules/.prisma/**/*"
  - "node_modules/@prisma/client/**/*"// or in jsextraResources:[
  "resources/database.db""node_modules/.prisma/**/*""node_modules/@prisma/client/**/*"
]

this solved `Error: cannot find module : '.prisma/client'

but this alone won't read DB in built exe file!

so in main.js where importing @prisma/client should change DB reading directory:

import { join } from'path';
const isProd = process.env.NODE_ENV === 'production';

import { PrismaClient } from'@prisma/client';
const prisma = newPrismaClient({
  datasources: {
    db: {
      url: `file:${isProd ? join(process.resourcesPath, 'resources/database.db') : join(__dirname, '../resources/database.db')}`,
    },
  },
})

with these configs I could fetch data from my sqlite DB

Post a Comment for "Electron-prisma Error: Can Not Find Module '.prisma/client'"