Windows 下的 electron 编译常见问题

Posted juwan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows 下的 electron 编译常见问题相关的知识,希望对你有一定的参考价值。

Windows系统编译

下载安装:
node v9.8.0
yarn-1.9.4
安装windows编译工具

npm install --global windows-build-tools

安装项目依赖

yarn install

开始编译,打包

npm run build
npm run release-win

常见错误

iojs.lib : fatal error LNK1106

c:userssuroudesktopscatterdesktop
ode_moduleskeccaksrclibkeccakKeccakSponge.h : warning C4819: ??????????????????????(936)?б????????????????????? Unicode ????????????? (???????? ..srclibkeccakKeccakSponge.c) [C:UsersSurouDesktopScatterDesktop
ode_moduleskeccakuildkeccak.vcxproj]
C:UsersSurou.electron-gyp.node-gypiojs-2.0.11x64iojs.lib : fatal error LNK1106: ?????Ч?????????: ???????? 0x29851C [C:UsersSurouDesktopScatterDesktop
ode_moduleskeccakuildkeccak.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)MSBuild14.0inmsbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:UsersSurouDesktopScatterDesktop
ode_modules
ode-gyplibuild.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:180:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Surou\Desktop\ScatterDesktop\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--target=2.0.11" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source"
gyp ERR! cwd C:UsersSurouDesktopScatterDesktop
ode_moduleskeccak
gyp ERR! node -v v9.8.0
gyp ERR! node-gyp -v v3.8.0

解决方案:删除 C:UsersSurou.electron-gyp
参考:https://github.com/electron/electron-rebuild/issues/163
app-builder.exe exited with code 1

Error: C:UsersSurouDesktopScatterDesktop
ode_modulesapp-builder-binwinx64app-builder.exe exited with code 1
  at ChildProcess.childProcess.once.code (C:UsersSurouDesktopScatterDesktop
ode_modulesuilder-utilsrcutil.ts:254:14)
  at Object.onceWrapper (events.js:272:13)
  at ChildProcess.emit (events.js:180:13)
  at maybeClose (internal/child_process.js:936:16)
  at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)

解决方案:删除node_modules,重新yarn install
参考:https://github.com/electron-userland/electron-builder/issues/2002
.binabylon: Error: ENOENT: no such file or directory

Cannot read file C:UsersSurouDesktopScatterDesktop
ode_modulesabylon.binabylon: Error: ENOENT: no such file or directory, open 'C:UsersSurouDesktopScatterDesktop
ode_modulesabylon.binabylon'
  at w (C:UsersSurouDesktopScatterDesktop
ode_modulesapp-builder-libsrcasarasarUtil.ts:201:11)
  at writeStream.write (C:UsersSurouDesktopScatterDesktop
ode_modulesapp-builder-libsrcasarasarUtil.ts:203:43)
  at afterWrite (_stream_writable.js:473:3)
  at onwrite (_stream_writable.js:464:7)
  at fs.write (fs.js:2252:5)-win: `electron-builder --win`
  at FSReqWrap.wrapper [as oncomplete] (fs.js:707:5)

解决方案:安装yarn-1.9.4版本
参考:https://github.com/GetScatter/ScatterDesktop/issues/165
编译完,运行,界面空白
经过反编译app.asar,发现缺少dist
解决方案:先运行npm run build,在运行npm run release-win

其他

反编译asar

npm install -g asar
asar extract app.asar ./

关联

https://www.bcskill.com/index.php/archives/476.html

以上是关于Windows 下的 electron 编译常见问题的主要内容,如果未能解决你的问题,请参考以下文章

Electron npm install 常见错误(Windows)

在 electron-vue 中的 Windows 下的路径问题,path.resolve 替换为 path.posix.join 。

Electron常见问题 55 - Electron 协议唤醒应用程序

Electron常见问题 55 - Electron 协议唤醒应用程序

Electron Atom - 编译后找不到模块“Node-Windows”

构建Electron的常见问题(Mac)