[英]Error when building my electron app
I'm stuck with a problem when building my Node JS/electron app with electron-builder .在使用electron-builder 构建Node JS/electron 应用程序时,我遇到了一个问题。 It works perfectly when running
npm start
.它在运行
npm start
时完美运行。 But, when I execute the command build -w
(for windows) it fails with this log .但是,当我执行命令
build -w
(对于 Windows)时,它会失败并显示此日志。
Here is my JSON file:这是我的 JSON 文件:
{
"name": "Munshiiii",
"version": "1.0.0",
"description": "This is a short Description of the project",
"main": "index.js",
"scripts": {
"start": "electron .",
"dist": "build -w"
},
"author": "Hicham Dbiza",
"license": "ISC",
"devDependencies": {
"electron": "1.7.8",
"electron-prebuilt": "^1.4.13"
},
"dependencies": {
"asar": "^0.13.0",
"cradle": "^0.7.1",
"fs": "0.0.1-security",
"git": "^0.1.5",
"jquery": "^3.2.1",
"jsdom": "^11.3.0",
"loke-ipc": "^1.0.5",
"mongodb": "^2.2.33",
"node-couchdb": "^1.2.0",
"pouchdb": "^6.3.4",
"pouchdb-replication-stream": "^1.2.9",
"scanner.js": "^1.0.0"
},
"build":{
"appId": "com.hicham.dbiza.faizan",
"win":{
"target": "nsis",
"icon": "build/Munshiiii.ico"
}
}
}
for this project Im using:对于这个项目,我使用:
I already used electron-packager and it works almost fine with one problem: See this picture , which means all links inside the js files (eg: fs.readFileSync('./assets/state','utf8')) won't work.我已经使用了电子打包器,它在一个问题上几乎可以正常工作:参见这张图片,这意味着 js 文件中的所有链接(例如:fs.readFileSync('./assets/state','utf8'))不会工作。 I have also added some native js click and keypress listeners... could that be a problem?
我还添加了一些本机 js 单击和按键侦听器……这可能是个问题吗?
My electron version is 1.7.8.我的电子版是 1.7.8。
I appreciate your help.我很感激你的帮助。
Yarn is strongly recommended instead of npm.强烈推荐用 Yarn 代替 npm。
yarn add electron-builder --dev
if you are using Npm如果你使用 Npm
do just simple steps terminal:只需简单的步骤终端:
1 npm install yarn -g
1
npm install yarn -g
2 yarn
2
yarn
3 yarn pack
3
yarn pack
Read this Blog (reactJS in electronApp with .exe file) 阅读此博客(带有 .exe 文件的电子应用程序中的 reactJS)
Have you installed electron-builder
?你安装了
electron-builder
吗? You don't have it in your package.json.您的 package.json 中没有它。 Then I would propose to use the
electron-builder
command, as recommended by the authors .然后我建议按照作者的建议使用
electron-builder
命令。
Run npm install electron-builder --save-dev
and change your dist
command to run just electron-builder
.运行
npm install electron-builder --save-dev
并将您的dist
命令更改为只运行electron-builder
。 Since electron-builder per default build for the current running OS, it's not necessary to send the -w
flag.由于当前运行的操作系统的默认构建是电子构建器,因此没有必要发送
-w
标志。 If you still experience problems, try to set the following env variable to get a better stack trace :如果您仍然遇到问题,请尝试设置以下环境变量以获得更好的堆栈跟踪:
DEBUG=electron-builder,electron-builder:*
Edit after getting more information from the comments: According to this issue at GitHub your first issue seemed to be caused by permission errors, and was solved with running as administrator.从评论中获取更多信息后进行编辑:根据GitHub 上的这个问题,您的第一个问题似乎是由权限错误引起的,并通过以管理员身份运行解决。
From electron-builders README :来自电子制造商自述文件:
Yarn is strongly recommended instead of npm.
yarn add electron-builder --dev
Try to remove your node_modules
folder and run尝试删除您的
node_modules
文件夹并运行
npm install yarn -g && yarn && yarn pack
First I installed electron-builder with following line首先,我使用以下行安装了电子生成器
npm install -g electron-builder
then I created a build folder in the root of my project, containing the .ico file with the app logo.然后我在项目的根目录中创建了一个 build 文件夹,其中包含带有应用程序徽标的 .ico 文件。 then I wrote following parts in my package.json
然后我在 package.json 中写了以下部分
"build": {
"appId": "your.app.id",
"productName": "Your final product name"
}
and和
"scripts": {
"start": "electron .",
"pack": "build --dir"
}
That was everything I needed.这就是我所需要的一切。 I opend my root folder in the terminal and executed
我在终端中打开我的根文件夹并执行
build -w
That created an folder called dist, with an unpacked version of my app plus an installer for the app.这创建了一个名为 dist 的文件夹,其中包含我的应用程序的解压缩版本以及应用程序的安装程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.