最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error when building my electron app - Stack Overflow

programmeradmin4浏览0评论

I'm stuck with a problem when building my Node JS/electron app with electron-builder. It works perfectly when running npm start. But, when I execute the mand build -w (for windows) it fails with this log.

Here is my JSON file:

{
  "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": ".hicham.dbiza.faizan",
    "win":{
        "target": "nsis",
        "icon": "build/Munshiiii.ico"
    }
  }
}

for this project Im using:

  • fs
  • pouchdb
  • electron
  • jquery
  • ....

I already used electron-packager and it works almost fine with one problem: See this picture, which means all links inside the js files (e.g: fs.readFileSync('./assets/state','utf8')) won't work. I have also added some native js click and keypress listeners... could that be a problem?

My electron version is 1.7.8.

I appreciate your help.

I'm stuck with a problem when building my Node JS/electron app with electron-builder. It works perfectly when running npm start. But, when I execute the mand build -w (for windows) it fails with this log.

Here is my JSON file:

{
  "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": ".hicham.dbiza.faizan",
    "win":{
        "target": "nsis",
        "icon": "build/Munshiiii.ico"
    }
  }
}

for this project Im using:

  • fs
  • pouchdb
  • electron
  • jquery
  • ....

I already used electron-packager and it works almost fine with one problem: See this picture, which means all links inside the js files (e.g: fs.readFileSync('./assets/state','utf8')) won't work. I have also added some native js click and keypress listeners... could that be a problem?

My electron version is 1.7.8.

I appreciate your help.

Share Improve this question edited Oct 21, 2017 at 22:36 toastrackengima 8,7914 gold badges53 silver badges62 bronze badges asked Oct 21, 2017 at 21:10 user8715216user8715216 211 gold badge1 silver badge3 bronze badges 4
  • What your electron version? please write in your question – Gabriel Commented Oct 21, 2017 at 21:26
  • My electron version is 1.7.8 – user8715216 Commented Oct 21, 2017 at 21:56
  • what is electron builder version.did you tried to use recent electron . try to change "dist": "build -w" to "dist": "build --win" – Jeya Kumar Commented Oct 22, 2017 at 9:36
  • done and still same problem :( – user8715216 Commented Oct 22, 2017 at 21:31
Add a ment  | 

4 Answers 4

Reset to default 1

Yarn is strongly remended instead of npm.

yarn add electron-builder --dev

if you are using Npm
do just simple steps terminal:

1 npm install yarn -g
2 yarn
3 yarn pack

Read this Blog (reactJS in electronApp with .exe file)

Have you installed electron-builder? You don't have it in your package.json. Then I would propose to use the electron-builder mand, as remended by the authors.

Run npm install electron-builder --save-dev and change your dist mand to run just electron-builder. Since electron-builder per default build for the current running OS, it's not necessary to send the -w flag. 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 ments: According to this issue at GitHub your first issue seemed to be caused by permission errors, and was solved with running as administrator.

From electron-builders README:

Yarn is strongly remended instead of npm.

yarn add electron-builder --dev

Try to remove your node_modules folder and run

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. then I wrote following parts in my 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.

I've encountered a similar issue where my app runs perfectly during development but throws an error during the build process, specifically:

ERROR: Cannot create symbolic link: A required privilege is not held by the client.

Here's what worked for me:

  • Try using Yarn instead of npm: While this didn't resolve the issue for me, it might work for others.

  • Enable Developer Mode on Windows:

  • This error often occurs because Windows doesn't allow the creation of symbolic links unless you have the necessary privileges.

  • To enable Developer Mode, go to Settings > System > for Developers > Developer Mode > switch Developer mode On. (for window 11)

发布评论

评论列表(0)

  1. 暂无评论