在ubuntu上构建电子应用失败,并显示“权限被拒绝”

时间:2018-12-03 10:59:21

标签: ubuntu electron building

我尝试使用' electron-builder '模块在ubuntu系统上构建电子项目,但是npm run dist始终会输出以下错误:

> project@1.0.0 dist /home/user/GitRepos/project
> build

sh: 1: build: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! project@1.0.0 dist: `build`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the project@1.0.0 dist script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2018-12-03T10_20_50_566Z-debug.log

我已经尝试使用sudo npm run dist,因为我认为我的用户可能只是不具备构建所需的权限,但却引起了完全相同的错误。

这是我的package.json中的脚本,依赖项和linux构建设置:

"scripts": {
  "start": "electron .",
  "pack": "build --dir",
  "dist": "build",
  "postinstall": "install-app-deps"
},
"dependencies": {
  "archiver": "^3.0.0",
  "electron-store": "^2.0.0",
  "popper.js": "^1.14.4",
  "unzipper": "^0.9.4"
},
"devDependencies": {
  "electron": "^3.0.10",
  "electron-builder": "^20.28.4"
},
"build": {
  "linux": {
    "target": [
      "AppImage",
      "deb"
    ]
  }
}

有人对Ubuntu上的电子有想法或经历过类似的事情吗?

P.S:如果需要更多信息,请随时询问!

2 个答案:

答案 0 :(得分:1)

尝试重新安装模块:

rm -rf node_modules && npm i

如果无效,请尝试设置构建脚本的可执行标志:

chmod +x "$(npm bin)/build"

答案 1 :(得分:0)

您也可以尝试

rm -rf dist

显然,如果以前有任何文件,可能没有足够的权限。