跳至主要內容

建置說明 (macOS)

請依照以下指南在 macOS 上建置 Electron 本身,以建立自訂的 Electron 二進位檔。如需使用預先建置的 Electron 二進位檔來捆綁和發佈您的應用程式程式碼,請參閱應用程式發佈指南。

先決條件

  • macOS >= 11.6.0
  • Xcode。所需的確切版本取決於您正在建置的分支,但最新版本的 Xcode 通常是建置 main 的好選擇。
  • node.js (外部)
  • Python >= 3.7

Arm64 特定的先決條件

  • Rosetta 2
    • 如果使用需要在 x64 和 arm64 機器上交叉編譯的相依性,我們建議安裝 Rosetta。可以使用 softwareupdate 命令列工具安裝 Rosetta。
    • $ softwareupdate --install-rosetta

建置 Electron

請參閱建置說明:GN

疑難排解

Xcode「不相容的架構」錯誤 (macOS arm64 特定)

如果 Xcode 和 Xcode 命令列工具都已安裝 ($ xcode -select --install,或直接從此處下載正確的版本),但堆疊追蹤另有指示,如下所示

xcrun: error: unable to load libxcrun
(dlopen(/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode.app/Contents/Developer/usr/lib/libxcrun.dylib), 0x0005):
tried: '/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode.app/Contents/Developer/usr/lib/libxcrun.dylib)'
(mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode-11.1.0.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode-11.1.0.app/Contents/Developer/usr/lib/libxcrun.dylib)' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))).`

如果您使用的是 arm64 架構,則建置腳本可能指向錯誤的 Xcode 版本 (11.x.y 不支援 arm64)。請前往 /Users/<user>/.electron_build_tools/third_party/Xcode/ 並將 Xcode-13.3.0.app 重新命名為 Xcode.app,以確保使用正確的 Xcode 版本。

憑證驗證失敗

安裝certifi將修正下列錯誤

________ running 'python3 src/tools/clang/scripts/update.py' in '/Users/<user>/electron'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 5 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 10 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 20 s ...

此問題與 Python 3.6 使用其自身的 OpenSSL 副本,而非已棄用的 Apple 提供的 OpenSSL 程式庫有關。certifi 會新增一個經過整理的預設根憑證組合。此問題記錄在 Electron 儲存庫此處。關於此問題的更多資訊,請參閱此處此處