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.
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:
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
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
meteor npm install canvas
meteor npm rebuild canvas --from-source-code
node -e "require('canvas')"
// result must be empty (without Error message)
Thanks a lot for help to @errorau