电子中的节点-canvas -- "mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed."

node-canvas in electron -- "mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed."

我正在使用 node-canvas.
创建电子应用程序 我通过以下命令生成了一个应用程序安装程序:

$ electron-builder --mac --x64 --config ./build_mac.js

build_mac.js

const config = {
  "appId": "jp.maplat.editor",
  "asarUnpack": [
    "assets/mac/canvas"
  ],
  "directories": {
    "output": "dist"
  },
  "files": [
    "assets/mac",
    "backend",
    "css",
    "frontend/dist",
    "html",
    "img",
    "locales",
    "package.json",
    "package-lock.json",
    "tms_list.json"
  ],
  "afterSign": "script/notarize/notarize.js",
  "mac": {
    "icon": "assets/mac/icon_mac.icns",
    "target": [
      "dmg"
    ],
    "hardenedRuntime": true,
    "gatekeeperAssess": false,
    "entitlements": "script/notarize/entitlements.mac.plist",
    "entitlementsInherit": "script/notarize/entitlements.mac.plist",
  },
  "win": {
    "icon": "assets/win/icon_win.ico",
    "target": "nsis"
  },
  "nsis":{
    "oneClick": false,
    "allowToChangeInstallationDirectory": true
  }
};

module.exports = config;

但是在安装 electron 应用程序后,该应用程序在 Web 控制台上输出以下错误消息:

Uncaught Error: dlopen(/Applications/MaplatEditor.app/Contents/Resources/app.asar.unpacked/assets/mac/canvas/build/Release/canvas.node, 1): Library not loaded: /usr/local/opt/pixman/lib/libpixman-1.0.dylib Referenced from: /Applications/MaplatEditor.app/Contents/Resources/app.asar.unpacked/assets/mac/canvas/build/Release/canvas.node Reason: no suitable image found. Did find: /usr/local/opt/pixman/lib/libpixman-1.0.dylib: code signature in (/usr/local/opt/pixman/lib/libpixman-1.0.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

如何解决? 我认为有 2 个问题,

  1. 如何签署这个dylib?
  2. 这个dylib看起来安装在“/usr/local/opt”下,它在应用程序文件夹之外。这是正确的预期行为吗?

有人知道这个问题的答案吗?

解决这个问题的方法是将所有dylibs(除了“/usr/lib”或“/System/Library/Frameworks”)放在电子控制的文件夹下。

在我的项目中是这样的: https://github.com/code4history/MaplatEditor/tree/master/assets/mac/canvas/build/Release

但是只放dylib是不行的,因为每个dylib都有link到其他库的信息

您可以使用“otool”命令检查每个 dylib linked 了哪些库,您可以使用“install_name_tool”命令覆盖它。

https://github.com/code4history/MaplatEditor/blob/master/mac_canvas_dylib

在这个 URL 中,您可以找到我为我的项目所做的工作。