在linux环境下对electron-egg项目打包失败该怎么解决?

刚开始报错是缺图标,我在publicbuild文件都放了图标,继续删除node_modules后打包还是报错,这种该怎么解决呢?
报错信息如下:

leadzone@vppfes2:~/wrrtest/mode/electron-egg$ npm run build-l

> ee@1.0.0 build-l
> electron-builder --config=./electron/config/builder.json --linux=deb --x64

  • electron-builder  version=23.6.0 os=4.19.0-11-linx-security-amd64
  • loaded configuration  file=/home/leadzone/wrrtest/mode/electron-egg/electron/config/builder.json
  • writing effective config  file=out/builder-effective-config.yaml
  • packaging       platform=linux arch=x64 electron=21.4.4 appOutDir=out/linux-unpacked
  • building        target=deb arch=x64 file=out/ee-linux-1.0.0-amd64.deb
  ⨯ unknown output format set
github.com/develar/app-builder/pkg/icons.convertSingleFile
    /Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:305
github.com/develar/app-builder/pkg/icons.doConvertIcon
    /Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:247
github.com/develar/app-builder/pkg/icons.ConvertIcon
    /Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:56
github.com/develar/app-builder/pkg/icons.ConfigureCommand.func1
    /Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:33
github.com/alecthomas/kingpin.(*actionMixin).applyActions
    /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/actions.go:28
github.com/alecthomas/kingpin.(*Application).applyActions
    /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:557
github.com/alecthomas/kingpin.(*Application).execute
    /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:390
github.com/alecthomas/kingpin.(*Application).Parse
    /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:222
main.main
    /Volumes/data/Documents/app-builder/main.go:90
runtime.main
    /usr/local/Cellar/go/1.17/libexec/src/runtime/proc.go:255
runtime.goexit
    /usr/local/Cellar/go/1.17/libexec/src/runtime/asm_amd64.s:1581  
  ⨯ /home/leadzone/wrrtest/mode/electron-egg/node_modules/app-builder-bin/linux/x64/app-builder process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Exit code:
1  failedTask=build stackTrace=Error: /home/leadzone/wrrtest/mode/electron-egg/node_modules/app-builder-bin/linux/x64/app-builder process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Exit code:
1
    at ChildProcess.<anonymous> (/home/leadzone/wrrtest/mode/electron-egg/node_modules/builder-util/src/util.ts:250:14)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1101:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

窗口配置

  /**
   * 主窗口
   */
  config.windowsOption = {
    title: "ee",
    width: 980,
    height: 650,
    minWidth: 400,
    minHeight: 300,
    webPreferences: {
      contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
      nodeIntegration: true,
    },
    frame: true, // 去除顶部任务栏/工具栏
    show: false,
    icon: path.join(appInfo.home, "public", "images", "logo.png"),
  };

build.json

{
  "productName": "ee",
  "appId": "com.electron.ee",
  "copyright": "© 2024 leadzorn Technology Co., Ltd.",
  "directories": {
    "output": "out"
  },
  "asar": true,
  "files": [
    "**/*",
    "!frontend/",
    "!run/",
    "!logs/",
    "!go/",
    "!python/",
    "!data/"
  ],
  "extraResources": {
    "from": "build/extraResources/",
    "to": "extraResources"
  },
  "nsis": {
    "oneClick": false,
    "allowElevation": true,
    "allowToChangeInstallationDirectory": true,
    "installerIcon": "build/icons/logo.ico",
    "uninstallerIcon": "build/icons/logo.ico",
    "installerHeaderIcon": "build/icons/logo.ico",
    "createDesktopShortcut": true,
    "createStartMenuShortcut": true,
    "shortcutName": "ee"
  },
  "mac": {
    "icon": "build/icons/logo.ico",
    "artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
    "darkModeSupport": true,
    "hardenedRuntime": false
  },
  "win": {
    "icon": "build/icons/logo.ico",
    "artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
    "target": [
      {
        "target": "nsis"
      }
    ]
  },
  "linux": {
    "icon": "public/images",
    "artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
    "target": [
      "deb"
    ],
    "category": "Utility"
  }
}

package.json

{
  "name": "ee",
  "version": "1.0.0",
  "homepage": "https://service.electron.build",
  "description": "A fast, desktop software development framework",
  "main": "main.js",
  "scripts": {
    "dev": "ee-bin dev",
    "dev-frontend": "ee-bin dev --serve=frontend",
    "dev-electron": "ee-bin dev --serve=electron",
    "dev-go": "ee-bin dev --serve=go",
    "dev-python": "ee-bin exec --cmds=python",
    "packager": "electron-packager ./ --platform=linux --arch=x64 --overwrite",
    "build-frontend": "ee-bin build --cmds=frontend && ee-bin move --flag=frontend_dist",
    "build-go-w": "ee-bin move --flag=go_static,go_config,go_package,go_images && ee-bin build --cmds=go_w",
    "build-go-m": "ee-bin move --flag=go_static,go_config,go_package,go_images && ee-bin build --cmds=go_m",
    "build-go-l": "ee-bin move --flag=go_static,go_config,go_package,go_images && ee-bin build --cmds=go_l",
    "build-python": "ee-bin build --cmds=python && ee-bin move --flag=python_dist",
    "start": "ee-bin start",
    "move": "ee-bin move --flag=go_static,go_config,go_package,go_images",
    "rd": "ee-bin move --flag=frontend_dist",
    "encrypt": "ee-bin encrypt",
    "clean": "ee-bin clean",
    "icon": "ee-bin icon",
    "reload": "nodemon --config ./electron/config/nodemon.json",
    "rebuild": "electron-rebuild",
    "re-sqlite": "electron-rebuild -f -w better-sqlite3",
    "build-w": "electron-builder --config=./electron/config/builder.json -w=nsis --x64",
    "build-w-32": "electron-builder --config=./electron/config/builder.json -w=nsis --ia32",
    "build-w-64": "electron-builder --config=./electron/config/builder.json -w=nsis --x64",
    "build-w-arm64": "electron-builder --config=./electron/config/builder.json -w=nsis --arm64",
    "build-we": "electron-builder --config=./electron/config/builder.json -w=portable --x64",
    "build-wz": "electron-builder --config=./electron/config/builder.json -w=7z --x64",
    "build-wz-32": "electron-builder --config=./electron/config/builder.json -w=7z --ia32",
    "build-wz-64": "electron-builder --config=./electron/config/builder.json -w=7z --x64",
    "build-wz-arm64": "electron-builder --config=./electron/config/builder.json -w=7z --arm64",
    "build-m": "electron-builder --config=./electron/config/builder.json -m",
    "build-m-arm64": "electron-builder --config=./electron/config/builder.json -m --arm64",
    "build-l": "electron-builder --config=./electron/config/builder.json --linux=deb --x64",
    "build-l-32": "electron-builder --config=./electron/config/builder.json -l=deb --ia32",
    "build-l-64": "electron-builder --config=./electron/config/builder.json --linux=deb --x64",
    "build-l-arm64": "electron-builder --config=./electron/config/builder.json --linux=deb --arm64",
    "build-l-armv7l": "electron-builder --config=./electron/config/builder.json -l=deb --armv7l",
    "build-lr-64": "electron-builder --config=./electron/config/builder.json -l=rpm --x64",
    "build-lp-64": "electron-builder --config=./electron/config/builder.json -l=pacman --x64",
    "test": "set DEBUG=* && electron . --env=local"
  },
阅读 291
avatarAI BotBETA

回答

这个错误提示表明在打包过程中图标处理出现了问题。具体错误是在处理图标文件时遇到了未知的输出格式。从错误信息来看,可能的原因和解决方案如下:

  1. 图标路径和格式问题

    • 确保图标文件路径正确无误。在 build.json 文件中,Linux 的图标配置路径应该是到具体的图标文件,而不是一个目录。例如,应该写成 "icon": "public/images/logo.png" 而不是 "icon": "public/images"
    • 确保图标文件格式正确。Linux 通常使用 PNG 格式的图标。
  2. 清理和重新安装依赖

    • 删除 node_modules 文件夹和 package-lock.json 文件(或 yarn.lock 文件,如果你使用的是 Yarn)。
    • 运行 npm install(或 yarn,如果你使用的是 Yarn)来重新安装依赖。
  3. 检查 electron-builder 版本

    • 确保你使用的 electron-builder 版本与 Electron 版本兼容。
    • 可以尝试更新 electron-builder 到最新版本。
  4. 尝试手动指定图标转换工具

    • 如果问题依然存在,可以尝试在 build.jsonelectron-builder 的配置中手动指定图标转换工具或参数。
  5. 查看详细的构建日志

    • 运行构建命令时,可以添加 --debug 或类似的选项来获取更详细的构建日志,这有助于进一步诊断问题。

修正后的 build.json 文件中 Linux 部分的配置应该类似于:

"linux": {
  "icon": "public/images/logo.png",
  "artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
  "target": [
    "deb"
  ],
  "category": "Utility"
}

按照这些步骤操作后,再次尝试打包,看看问题是否得到解决。如果问题依然存在,可能需要更详细地检查构建配置或代码中的其他潜在问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏