簡體   English   中英

在 Mac M1 上使用節點 Canvas 部署 Firebase Cloud-Function 失敗

[英]Deploy Firebase Cloud-Function with Node Canvas fails on Mac M1

我剛買了一台新的 Mac M1,我正在嘗試部署一個 Firebase 雲 Function。它工作正常,只要我不包括節點 canvas 模塊。

當我嘗試部署時,出現以下錯誤:

Error: Error occurred while parsing your function triggers.

Error: dlopen(/Library/WebServer/Documents/inklay_web_cf/functions/node_modules/canvas/build/Release/canvas.node, 0x0001): tried: '/Library/WebServer/Documents/inklay_web_cf/functions/node_modules/canvas/build/Release/canvas.node' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/canvas.node' (no such file), '/usr/lib/canvas.node' (no such file)
    at tryImporting (pkg/prelude/bootstrap.js:1736:37)
    at process.dlopen (pkg/prelude/bootstrap.js:1762:5)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1186:18)
    at Module.load (internal/modules/cjs/loader.js:984:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module.require (pkg/prelude/bootstrap.js:1338:31)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Library/WebServer/Documents/inklay_web_cf/functions/node_modules/canvas/lib/bindings.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1136:30)
vonnielu@lukass-macbook-pro-1 functions % node-gyp rebuild
zsh: command not found: node-gyp

看來,Firebase Cloud Function 不喜歡這個架構。 但是我能做什么? 非常歡迎任何幫助。

節點:v16.14.0 Firebase 工具:10.2.0 Mac OS Monterey:12.2.1 Apple M1 Max

我通過以下方式解決了問題:

  • 將節點版本降級到 v12.22.10

  • 刪除我的項目文件夾中的所有 node_modules

  • 在 vs 代碼中運行 rosetta 終端

  • npm 安裝

  • 刪除我的雲功能(部署所有功能取消注釋)

  • 部署我的雲功能(firebase 部署)

遲到的答案:面對與 Apple M1 芯片(arm64 架構)相同類型的問題,我發現了為什么涉及我的節點版本:

  • 即使是很小的節點版本更改也會出現我的問題,這取決於我使用的工具/編輯器(花了我幾周的時間)
  • 安裝的不同節點版本是為不同的處理器架構編譯的:16.3.0 是 x86_64,16.15.0 是 arm64。 最終,在我將機器從基於 x86 的機器更改為基於 arm64 的機器之前安裝了一個(我可能轉移了我的備份,並且為我的新架構啟動或編譯了下一個版本
  • canvas 不知何故是系統的 x64_64,所以只與 x86_64 節點安裝兼容

我現在正在尋找 2 個解決方案,要么我在 x64 中使用以前的節點,要么我在我的 package.json(干凈的方式,恕我直言)中系統地找到如何為 arm64/本地 arch 獲取 canvas。 (第三種方式:x64 上的新節點但也不干凈)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM