I write an Electron app that uses nodegit. For my test part I use ava in combination with Spectron to test my app. All of my tests work - including functions which use nodegit in my app.
In addition to the tests described above I made also a pure non-Electron test file in which I import nodegit directly.
import * as nodegit from 'nodegit';
Executing this test now via ava returns this:
node_modules\.pnpm\nodegit@0.27.0\node_modules\nodegit\build\Release\nodegit.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 82. This version of Node.js requires
NODE_MODULE_VERSION 83. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Module._extensions..node (internal/modules/cjs/loader.js:1122:18)
Where exactly does version 82 come from? I only have nodejs 14.15.0
installed, which uses version 83
as expected. Why does node think the version is a mismatch where it works actually in my app? This is how my package.json
looks like:
"devDependencies": {
"ava": "^3.13.0",
},
"scripts": {
"ava": "node_modules/.bin/ava",
...
},
"ava": {
"files": [
"*.ts"
],
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"nodeArguments": [
"--napi-modules",
"--experimental-modules"
]
},
I built nodegit
myself and in the config.gypi
file it even refers to:
"node_module_version": 83,
I made a super simple reproducible example: https://github.com/Githubber2021/node_module_version-issue
% node --version
14.15.0
% npm install
% npm run ava
... error
Can anyone explain me if this a bug or where version 82 comes from?
The answer is already solve, just adding one approach.
As mention, the ABI (application binary interface) of your Node.Js could be diff from the ABI of the Node.js used by Electron, regardless of the version of each Node.js.
So you install a native module using NPM that builds OK using the Node.js you have with the corresponding NODE_MODULE_VERSION (ABI), but when Electron try to use it, you get an error asking your module to use the ABI version of the Node.js included in Electron.
The other approach:
Install modules like any other Node project, then rebuild for Electron with the electron-rebuild package.
npm install --save-dev electron-rebuild
./node_modules/.bin/electron-rebuild
Notes