You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:启动经签名公证的Electron-Forge macOS应用时出现主进程错误

解决Electron-Forge macOS应用签名公证后sqlite3加载失败的问题

问题根源

签名公证后,macOS的代码签名验证机制要求所有加载的二进制文件(包括sqlite3的.node模块)的Team ID必须和主应用一致。未签名时系统跳过验证,所以能正常运行;签名后验证规则严格,就触发了Team ID不匹配的错误。

解决方案步骤

  • 重新编译sqlite3匹配Electron版本
    避免使用默认预编译二进制,确保模块适配当前Electron环境:

    npx electron-rebuild -f -w sqlite3
    
  • 配置Electron-Forge自动签名参数
    在forge.config.js(或forge.config.ts)的packagerConfig中,完善osxSign配置,让签名流程覆盖sqlite3模块:

    module.exports = {
      packagerConfig: {
        osxSign: {
          identity: "你的开发者证书名称",
          hardenedRuntime: true,
          entitlements: "./entitlements.plist",
          entitlementsInherit: "./entitlements.plist",
          signingTime: true,
          gatekeeperAssess: false
        },
        osxNotarize: {
          appleId: "你的Apple ID",
          appleIdPassword: "你的App专用密码",
          teamId: "你的Team ID"
        }
      }
    };
    
  • 配置权限文件entitlements.plist
    创建或修改该文件,添加必要权限以兼容第三方二进制加载:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>com.apple.security.cs.allow-jit</key>
      <true/>
      <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
      <true/>
      <key>com.apple.security.cs.disable-library-validation</key>
      <true/>
    </dict>
    </plist>
    

    注:com.apple.security.cs.disable-library-validation是兜底选项,优先确保前两步让sqlite3用相同Team ID签名,必要时再启用该权限。

  • 手动补签sqlite3模块(自动签名失效时)
    如果自动签名未覆盖.node文件,执行手动签名命令:

    codesign --force --deep --sign "你的开发者证书ID" ./node_modules/sqlite3/lib/binding/electron-vXX-darwin-x64/node_sqlite3.node
    

    替换electron-vXX-darwin-x64为实际Electron版本对应的路径,证书ID可通过security find-identity -v -p codesigning查看。

  • 重新打包并完成签名公证
    执行构建命令重新生成应用,再走签名公证流程:

    npm run make
    

内容的提问来源于stack exchange,提问作者MichaelB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 22:22:41