0

I'm getting the following error on Mac with M1 CPU:

I'm unable to build nodejs app with 'node-canvas' npm package, because Error: dlopen(/Users/..../node_modules/canvas/build/Release/canvas.node, 0x0001): tried: '/Users/..../node_modules/canvas/build/Release/canvas.node' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/..../node_modules/canvas/build/Release/canvas.node' (no such file), '/Users/..../node_modules/canvas/build/Release/canvas.node' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I installed brew canvas dependencies: brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

I also set following path: export PKG_CONFIG_PATH="/opt/homebrew/opt/pixman/lib/pkgconfig"

I also tried to rebuild from source-codes: npm install --build-from-source

I also removed and installed again canvas package:

rm -rf node_modules package-lock.json npm install

But still I'm getting the same error related to arm64 architecture.

notice:

nodejs is installed with nvm
nodejs version: v22.11.0
nvm version: 0.39.7

Thanks for help.

2 Answers 2

1

To fix the node-canvas build issue on your M1 Mac:

Reinstall Node.js for ARM64:

nvm uninstall v22.11.0
arch -arm64 nvm install v22.11.0

Install Dependencies for ARM64:

brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman

export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:/opt/homebrew/opt/pixman/lib/pkgconfig"

Clean Reinstall Canvas:

rm -rf node_modules package-lock.json
npm install
npm rebuild canvas --build-from-source

for result

node -e "require('canvas')"
2
  • Thanks a lot @errorau, I followed your instructions and when I will use 'npm rebuild canvas --build-from-source' => node -e "require('canvas')" it works without error, BUT: when do the same from meteor.js framework 'meteor npm rebuild canvas --build-from-source' => meteor node -e "require('canvas')" I still get the same error related to architecture :-(
    – klaucode
    Commented Nov 25 at 10:27
  • Helloe @errorau, together with your recommendations I found, that on Meteor 3.0.4 canvas package works and on Meteor 3.1 (latest) it's getting those error.
    – klaucode
    Commented Nov 25 at 11:46
0

The problem was found with Meteor nodejs, which after update was change from arm64 to incorrect x64 platform. Current nodejs platform you can simple validate by: meteor node -p "process.arch" (correct result for M1: arm64)

If the result is incorrect (x64) continue by following steps:

1. Reinstall Meteor.js
cd
rm -rf meteor
curl https://install.meteor.com/\?release\=3.1 | sh
cd <your project folder>
rm -rf node_modules package-lock.json
meteor update
meteor update --all-packages
meteor npm install
2. Install canvas prerequisities
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
3. Install and rebuild canvas package
meteor npm install canvas
meteor npm rebuild canvas --from-source-code
4. Validate canvas package
node -e "require('canvas')"
// result must be empty (without Error message)

Thanks a lot for help to @errorau

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.