Today I was trying to install sharp with yarn add sharp to work in my electron app, but I get the following error
Uncaught Error: The module '/Users/khoa/MyElectronApp/node_modules/sharp/build/Release/sharp.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing
the module
Node.js Addons are dynamically-linked shared objects, written in C++, that can be loaded into Node.js using the require() function, and used just as if they were an ordinary Node.js module. They are used primarily to provide an interface between JavaScript running in Node.js and C/C++ libraries.
I'm using nvm to manage node version, and nvm list shows 8.4.0 as the latest node version I'm using.
v6.10.1
v7.8.0
v7.9.0
v8.0.0
-> v8.4.0
system
Searching on Node releases reveals that Node 8.4.0 has NODE_MODULE_VERSION of 57, so that is the node version npm uses to compile sharp
However, I can't seem to find the NODE_MODULE_VERSION 54 that sharp is using. I tried node 8.0.0 which is believed to have NODE_MODULE_VERSION 54 but it didn't work
NODE_MODULE_VERSION
Today I was trying to install sharp with
yarn add sharp
to work in my electron app, but I get the following errorNative node module
Searching a bit, it was because
sharp
is a native node module which uses libvips under the hoodMore on how to build native node module can be found here https://blog.risingstack.com/writing-native-node-js-modules/
Node version
I'm using nvm to manage node version, and
nvm list
shows8.4.0
as the latest node version I'm using.Searching on Node releases reveals that Node 8.4.0 has
NODE_MODULE_VERSION
of 57, so that is the node version npm uses to compilesharp
However, I can't seem to find the
NODE_MODULE_VERSION
54 thatsharp
is using. I tried node8.0.0
which is believed to haveNODE_MODULE_VERSION
54 but it didn't workElectron version
As the time of this post,
electron
is at version7.9.0
, you can check here https://github.com/electron/electron/blob/master/.node-version or by runningprocess.versions
in Javascript consoleUsing electron-rebuild
So after I read this Using Native Node Modules, I install
electron-rebuilder
to recompilesharp
It works now 🎉
Read more