[英]Error importing a user js file using electron-builder
I have an electron application with main process as follows:我有一个电子申请,主要流程如下:
const {app, BrowserWindow, Menu, dialog} = require('electron');
const path = require('path')
let logConfig = require('./js/loggConfig.js');
....
This executes perfectly when run directly from terminal.当直接从终端运行时,这可以完美执行。
But when I package this project using electron-builder, and install it on another machine (Windows 10), I get the following error while launching the app: Error: Cannot find module '.js/loggConfig.js'
但是当我使用 electron-builder 打包这个项目并将其安装在另一台机器(Windows 10)上时,我在启动应用程序时收到以下错误:
Error: Cannot find module '.js/loggConfig.js'
How do I resolve this?我该如何解决这个问题?
Here is how my package.json
looks like:这是我的
package.json
的样子:
{
"name": "ABCD",
"version": "0.0.1",
"description": "...",
"author": "abcd <abcd@gmail.com>",
"homepage": "http://www.abcd.com",
"main": "main_electron.js",
"scripts": {
"postinstall": "install-app-deps",
"start": "electron .",
"dist": "build"
},
"build": {
"appId": "yourappid",
"dmg": {
"contents": [
{
"x": 110,
"y": 150
},
{
"x": 240,
"y": 150,
"type": "link",
"path": "/Applications"
}
]
},
"linux": {
"target": [
"AppImage",
"deb"
],
"category": "Video"
},
"win": {
"target": "NSIS",
"icon": "build/icon.ico",
"extraResources": [
]
}
},
"dependencies": {
"electron-context-menu": "^0.9.1",
"electron-log": "^2.2.13",
"fs": "0.0.1-security",
"mkdirp": "^0.5.1",
"path": "^0.12.7",
"uuid": "^3.1.0",
"xmlbuilder": "^9.0.4",
"zip-folder": "^1.0.0"
},
"devDependencies": {
"electron": "^1.7.9",
"electron-builder": "^19.49.0"
}
}
I solved the issue changing the build configuration.我解决了更改构建配置的问题。
asar
to false
.asar
设置为false
。asarUnpack
to export all the asar
content with "**/*"
.asarUnpack
以使用"**/*"
导出所有asar
内容。 "build": {
"appId": "app.node.electron",
"productName": "app electron",
"asar":false,
"asarUnpack":[
"**/*"
],
"directories": {
"output": "release"
},
"win": {
"publisherName": "app electron",
"icon": "icon.png",
"target": [
"nsis"
]
},
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.