sharp: Mismatched x64 and ARM64 architectures on M1 Mac

I had installed sharp 0.27.1 earlier today on my M1 Mac and used it without problems for several hours, resizing and converting various images.

Then a few hours ago I was changing some yarn packages and sharp stopped working all of a sudden, and I was getting this message whenever I ran a node script with require("sharp")

$ node processPhotos.js
/Users/longzheng/Documents/GitHub/photos/node_modules/sharp/lib/constructor.js:34
  throw new Error(error);
  ^

Error: 
Something went wrong installing the "sharp" module

dlopen(/Users/longzheng/Documents/GitHub/photos/node_modules/sharp/build/Release/sharp.node, 1): Symbol not found: __ZTVN4vips7VOptionE
  Referenced from: /Users/longzheng/Documents/GitHub/photos/node_modules/sharp/build/Release/sharp.node
  Expected in: flat namespace
 in /Users/longzheng/Documents/GitHub/photos/node_modules/sharp/build/Release/sharp.node

- Remove the "node_modules/sharp" directory then run
  "npm install --ignore-scripts=false --verbose" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues

    at Object.<anonymous> (/Users/longzheng/Documents/GitHub/photos/node_modules/sharp/lib/constructor.js:34:9)
    at Module._compile (node:internal/modules/cjs/loader:1091:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
    at Module.load (node:internal/modules/cjs/loader:971:32)
    at Function.Module._load (node:internal/modules/cjs/loader:812:14)
    at Module.require (node:internal/modules/cjs/loader:995:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/longzheng/Documents/GitHub/photos/node_modules/sharp/lib/index.js:3:15)
    at Module._compile (node:internal/modules/cjs/loader:1091:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I’ve tried various troubleshooting steps without any effect

  • reinstalling vips with brew reinstall vips
  • reinstalling sharp with yarn add --force sharp
  • clearing yarn cache with yarn cache clear
  • deleting node_modules and reinstalling packages with yarn install
  • restarting macOS

My env

% npx envinfo --binaries --system

  System:
    OS: macOS 11.2.1
    CPU: (8) x64 Apple M1
    Memory: 37.70 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.9.0 - /usr/local/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 7.5.3 - /usr/local/bin/npm

I’m completely dumbfounded why it was working well then suddenly stopped working.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

That’s so weird, I don’t know how I ended up in this state. 😕 I thought I had been using the arm64 version of vips when it sounds like I wasn’t.

brew remove vips
rm -rf node_modules
yarn install

and now sharp works correctly.

Thanks for your advice.