Error: The module sharp was compiled against a different Node.js version


#1

Hello, I’m trying to set up my first CircleCI builds, after a first try I got the build working (it’s a Node app using the Gatsby static site generator), but upon rebuild I every time have the error below:

Error: The module '/home/circleci/repo/node_modules/sharp/build/Release/sharp.  node'
  was compiled against a different Node.js version using
  NODE_MODULE_VERSION 51. This version of Node.js requires
  NODE_MODULE_VERSION 59. Please try re-compiling or re-installing
  the module (for instance, using `npm rebuild` or `npm install`).

If I “rebuild without cache”, the error is fixed. But of course I can’t do that every time.

Sharp is an image manipulation library which is a dependency of Gatsby and it needs to compile some native code. However I don’t understand the error because the previous build was made in the exact same conditions on CircleCI. Would anyone know how to debug this? Thanks very much.


#2

@levlaz would you have any idea about this, by chance? :slightly_smiling_face:


#3

This appears to be a bug in yarn 1.3.2 leading to the wrong node-gyp version being used, thus the transitive dep gatsby>sharp>libvips not being compiled properly. I workarounded by adding npm rebuild after yarn install in the config shown in the OP (as the error message suggested). Will monitor https://github.com/yarnpkg/yarn/issues/5152 for proper fix.


#4