电子棱镜错误:找不到模块';.棱镜/客户端';
我正在构建一个Nuxt-Electronics-Prisma应用程序,我有点被困在这里了。当我按照指导正常使用Prisma时,在dev上一切正常,但是在build上我得到这个错误:
A javascript error occurred in the main process
Uncaught exception:
Error: can not find module : '.prisma/client'
我尝试将Prisma提供程序输出更改为../resources/prisma/client
generator client {
provider = "prisma-client-js"
output = "../resources/prisma/client"
}
和电子的main.js
const { PrismaClient } = require('../resources/prisma/client');
const prisma = new PrismaClient()
但是我在开发和内部版本中都收到错误Cannot find module '_http_common' at webpackMissingModules
!其他人认为这是在客户端使用Prisma时引起的,但我只在background.js
(我的样板中的main.js
)使用它
我对Nuxt-Electronics使用Nuxtron样板,它使用YML文件作为电子生成器配置文件,并且在其中我还将Prisma添加到文件属性:
appId: com.example.app
productName: nuxt-electron-prisma
copyright: Copyright © 2021
nsis:
oneClick: false
perMachine: true
allowToChangeInstallationDirectory: true
directories:
output: dist
buildResources: resources
files:
- "resources/prisma/database.db"
- "node_modules/.prisma/**"
- "node_modules/@prisma/client/**"
- from: .
filter:
- package.json
- app
publish: null
但仍收到错误
在我的win-unpacked/resources
中,我只有以下内容:win-unpackedesourcesapp.asar.unpacked
ode_modules@prismaengines
当然还有我的Package.json
{
"private": true,
"name": "nuxt-electron-prisma",
"productName": "nuxt-electron-prisma",
"description": "",
"version": "1.0.0",
"author": "",
"main": "app/background.js",
"scripts": {
"dev": "nuxtron",
"build": "nuxtron build"
},
"dependencies": {
"electron-serve": "^1.0.0",
"electron-store": "^6.0.1",
"@prisma/client": "^3.0.2"
},
"devDependencies": {
"@mdi/font": "^6.1.95",
"@nuxtjs/axios": "^5.13.6",
"@nuxtjs/device": "^2.1.0",
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/vuetify": "1.12.1",
"core-js": "^3.15.1",
"electron": "^10.1.5",
"electron-builder": "^22.9.1",
"glob": "^7.1.7",
"noty": "^3.2.0-beta",
"nuxt": "^2.15.7",
"nuxtron": "^0.3.1",
"sass": "1.32.13",
"swiper": "^5.4.5",
"prisma": "^3.0.2",
"vue-awesome-swiper": "^4.1.1"
}
}
解决方案
Mojtaba Barari提供的solution可以工作,但它导致resources/app/node_modules
和resources/node_modules
中都存在@prisma
包。
有更好的方法:
{
"build": {
"extraResources": [
{
"from": "node_modules/.prisma/client/",
"to": "app/node_modules/.prisma/client/"
}
],
}
}
在这种情况下,Prisma客户端文件将直接复制到已存在其他@prisma
包的resources/app/node_modules
,因此与其他解决方案相比,您将节省约10 MB。
编辑:
如果将应用程序打包到asar存档中,我之前的解决方案将不起作用。您需要改用files
字段:
{
"build": {
"files": [
{
"from": "node_modules/.prisma/client/",
"to": "node_modules/.prisma/client/"
}
],
}
}
这是一个通用解决方案,即使您不使用ASAR存档也可以使用。
相关文章