windows中electron,使用electron-builder构建时由于文件过大导致构建失败解决方案

electron build的错误示例

ExecError: C:\Users\User007\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin\makensis.exe exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Output:
Command line defined: "APP_ID=com.electron.demo-project"
Command line defined: "APP_GUID=2368610f-177f-5f33-9b73-283da6803b10"
Command line defined: "UNINSTALL_APP_KEY=2368610f-177f-5f33-9b73-283da6803b10"
Command line defined: "PRODUCT_NAME=showroom"
Command line defined: "PRODUCT_FILENAME=showroom"
Command line defined: "APP_FILENAME=demo-project"
Command line defined: "APP_DESCRIPTION="
Command line defined: "VERSION=1.0.9"
Command line defined: "PROJECT_DIR=C:\project\demo-project-web"
Command line defined: "BUILD_RESOURCES_DIR=C:\project\demo-project-web\build"
Command line defined: "APP_PACKAGE_NAME=demo-project"
Command line defined: "APP_64=C:\project\demo-project-web\dist_electron\demo-project-1.0.9-x64.nsis.7z"
Command line defined: "APP_64_NAME=demo-project-1.0.9-x64.nsis.7z"
Command line defined: "APP_64_HASH=27D7FC29BDA9EB1B72A59F451306CAD4D3C26A1A3B932C4A214589CF377FB715F02242B7602809A904C01B2E787345A8D08ED33215F5421149D70FE730F2D3BC"
Command line defined: "APP_PRODUCT_FILENAME=showroom"
Command line defined: "APP_INSTALLER_STORE_FILE=demo-project-updater\installer.exe"
Command line defined: "COMPRESSION_METHOD=7z"
Command line defined: "ONE_CLICK"
Command line defined: "RUN_AFTER_FINISH"
Command line defined: "SHORTCUT_NAME=showroom"
Command line defined: "UNINSTALL_DISPLAY_NAME=showroom 1.0.9"
Command line defined: "ESTIMATED_SIZE=2689691"
Command line defined: "COMPRESS=auto"
Command line defined: "UNINSTALLER_OUT_FILE=C:\project\demo-project-web\dist_electron\__uninstaller-nsis-demo-project.exe"
Processing config: C:\Users\User007\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\nsisconf.nsh
Processing script file: "" (ACP)

Error output:
File: failed creating mmap of "C:\project\demo-project-web\dist_electron\demo-project-1.0.9-x64.nsis.7z"
Error in macro x64_app_files on macroline 1
Error in macro compute_files_for_current_arch on macroline 7
Error in macro extractEmbeddedAppPackage on macroline 8
Error in macro installApplicationFiles on macroline 79
!include: error in script: "installSection.nsh" on line 63
Error in script "" on line 189 -- aborting creation process

    at ChildProcess.<anonymous> (C:\project\demo-project-web\node_modules\builder-util\src\util.ts:250:14)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.cp.emit (C:\project\demo-project-web\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1100:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) {
  exitCode: 1,
  alreadyLogged: false,
  code: 'ERR_ELECTRON_BUILDER_CANNOT_EXECUTE'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

错误原因

  • 工程资源文件(如public中的mp4资源)过大,整个打包起来超过2GB以上,导致electron-builder进行7z压缩时失败
    File: failed creating mmap of "C:\project\demo-project-web\dist_electron\demo-project-1.0.9-x64.nsis.7z"

可以在electron打包的dist目录观察xxxxxxxxxx.nsis.7z在打包过程中的变化

  • windows的版本才会出现打包2GB限制

解决方案

错误示例中,使用这个C:\Users\User007\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin\makensis.exe工具进行打包,此工具限制了2BG的打包,使用不受2GB限制的nsis包覆盖原包即可

  1. 进入C:\Users\User007\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1目录下
  2. 下载nsis解除2GB限制压缩包点击链接下载
  3. 解压并将文件覆盖到C:\Users\User007\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1目录下
  4. 再次构建,不出意外的话,是可以正常build了

你可能感兴趣的:(windows,electron,javascript)