第一次使用eletron开发桌面应用就碰到了坑
首先npm install时就会特别慢
应该使用cnpm install安装依赖包
此时报错
[npminstall:runscript:error] electron-forge@5.2.4 › electron-installer-dmg@0.2.1 › appdmg@0.4.5 › fs-xattr@^0.1.14 has binding.gyp file, run "node-gyp rebuild" error: Error [RunScriptError]: Run "sh -c node-gyp rebuild" error, exit code 1
at ChildProcess.<anonymous> (/usr/local/lib/node_modules/cnpm/node_modules/runscript/index.js:96:21)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
name: 'RunScriptError',
stdio: [Object]
说的应该是这几个模块没有装成功,于是分别开始安装这几个模块
当安装cnpm install appdmg@0.4.5时又报错
[npminstall:runscript:error] appdmg@0.4.5 › fs-xattr@^0.1.14 has binding.gyp file, run "node-gyp rebuild" error: Error [RunScriptError]: Run "sh -c node-gyp rebuild" error, exit code 1
at ChildProcess.<anonymous> (/usr/local/lib/node_modules/cnpm/node_modules/runscript/index.js:96:21)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
name: 'RunScriptError',
stdio: [Object]
}
✖ Install fail! RunScriptError: Run "sh -c node-gyp rebuild" error, exit code 1
RunScriptError: Run "sh -c node-gyp rebuild" error, exit code 1
at ChildProcess.<anonymous> (/usr/local/lib/node_modules/cnpm/node_modules/runscript/index.js:96:21)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
npminstall version: 3.27.0
npminstall args: /usr/local/bin/node /usr/local/lib/node_modules/cnpm/node_modules/npminstall/bin/install.js --fix-bug-versions --china --userconfig=/Users/xiaobei/.cnpmrc --disturl=https://npm.taobao.org/mirrors/node --registry=https://r.npm.taobao.org appdmg@0.4.5
网上搜了一下他出现的问题是和python版本有关
然而我也指定了python版本安装
sudo npm install -g appdmg --python=python2.7
此时又报错了
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/Users/xiaobei/Library/Caches/node-gyp/12.13.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/appdmg/node_modules/macos-alias/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/appdmg/node_modules/macos-alias/.node-gyp'
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/appdmg/node_modules/macos-alias
看着应该还是和权限有关
网上搜了一下加了个参数安装
sudo npm install -g appdmg --python=python2.7 --unsafe-perm
安装成功