简体   繁体   English

运行项目时节点 Canvas 抛出错误

[英]Node Canvas throwing error when running project

Node Canvas is not working for me on m1节点 Canvas 在 m1 上不适合我

When I try to run my project I get this error message:当我尝试运行我的项目时,我收到以下错误消息:

Error: dlopen(.../node_modules/canvas/build/Release/canvas.node, 0x0001): tried: '.../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)

Already did:已经做了:

brew install pkg-config cairo pango libpng jpeg giflib librsvg

xcode-select --install

npm i canvas

With no errors没有错误

Not sure how to debug this as there are people with Node Canvas working on m1 laptops, please help.不确定如何调试此问题,因为有人使用 Node Canvas 在 m1 笔记本电脑上工作,请帮忙。

The most important thing is to make sure your Node executable has been compiled for Apple Silicon, meaning there's a pre-built binary for darwin-arm64 .最重要的是确保您的 Node 可执行文件已针对 Apple Silicon 编译,这意味着darwin-arm64有一个预构建的二进制文件。 You can see which versions have which binaries here (the following page has the binaries for Node version 16.13.1): https://nodejs.org/download/release/v16.13.1/ .您可以在此处查看哪些版本具有哪些二进制文件(以下页面包含 Node 版本 16.13.1 的二进制文件): https://nodejs.org/download/release/v16.13.1/

Node v14 has no pre-built binaries for darwin-arm64 (see https://github.com/nodejs/node/issues/36161 ), because it can't be compiled natively to Apple Silicon. Node v14 没有用于darwin-arm64的预构建二进制文件(请参阅https://github.com/nodejs/node/issues/36161 ),因为它不能本地编译到 Apple Silicon。

I use volta ( https://volta.sh/ ) to manage my Node versions, so if you install Node v16 with volta install node@16 and then run npm i canvas , you should get a correctly compiled canvas.node file. I use volta ( https://volta.sh/ ) to manage my Node versions, so if you install Node v16 with volta install node@16 and then run npm i canvas , you should get a correctly compiled canvas.node file.

If that fails, go to node_modules/canvas and run npm install --build-from-source , which will compile the C++ addon and output the corect canvas.node . If that fails, go to node_modules/canvas and run npm install --build-from-source , which will compile the C++ addon and output the corect canvas.node .

You can check this by running:您可以通过运行检查这一点:

file node_modules/canvas/build/Release/canvas.node
# outputs: node_modules/canvas/build/Release/canvas.node: Mach-O 64-bit bundle arm64

If it says arm64 at the end, then you're good to go.如果它最后说arm64 ,那么你对 go 很好。 If it still says x86_64 , then something went wrong.如果它仍然显示x86_64 ,那么就出了问题。

I use npm install --build-from-source .我使用npm install --build-from-source It work!这行得通!

But there are new mistakes但是有新的错误

dlopen(.../node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace '_cairo_fill' dlopen(.../node_modules/canvas/build/Release/canvas.node,0x0001):在平面命名空间“_cairo_fill”中找不到符号

I have run into a new issue after npm install --build-from-sourcenpm install --build-from-source之后我遇到了一个新问题

dlopen(.../node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace '_cairo_fill' dlopen(.../node_modules/canvas/build/Release/canvas.node,0x0001):在平面命名空间“_cairo_fill”中找不到符号

Have anyone fixed this?有人修过这个吗?

Any solutions for this?有什么解决方案吗?

dlopen(.../node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace '_cairo_fill' dlopen(.../node_modules/canvas/build/Release/canvas.node,0x0001):在平面命名空间“_cairo_fill”中找不到符号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM