help icon indicating copy to clipboard operation
help copied to clipboard

Incorrect NODE_MODULE_VERSION when using a test framework

Open MMcKester opened this issue 5 years ago • 11 comments

  • Version: node 14.15.0
  • Platform: Windows

What steps will reproduce the bug?

Simply clone and execute the commands below: https://github.com/Githubber2021/node_module_version-issue

% node --version
14.15.0
% npm install
% npm run ava
... error

In an ava test I try to import nodegit.

 import * as nodegit from 'nodegit';

which fails with this error message:

node_modules\.pnpm\[email protected]\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 node 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,

Can anyone explain me if this a bug? Where version 82 comes from?

MMcKester avatar Nov 12 '20 15:11 MMcKester

Can anyone explain me if this a bug? Where version 82 comes from?

@Githubber2021 82 is from Electron (https://github.com/nodejs/node/blob/c1442ec9c45cecf156fb32ad2174c4aceef37de7/doc/abi_version_registry.json#L9) and suggests that your tests were installed with/compiled for the version of Node.js that Electron provides.

richardlau avatar Nov 12 '20 16:11 richardlau

Can anyone explain me if this a bug? Where version 82 comes from?

@Githubber2021 82 is from Electron (https://github.com/nodejs/node/blob/c1442ec9c45cecf156fb32ad2174c4aceef37de7/doc/abi_version_registry.json#L9) and suggests that your tests were installed with/compiled for the version of Node.js that Electron provides.

Thank you so much! But I’m wondering, if I use nodegit in Electron it works. Isn’t that suspicious?

MMcKester avatar Nov 12 '20 17:11 MMcKester

Can anyone explain me if this a bug? Where version 82 comes from?

@Githubber2021 82 is from Electron (https://github.com/nodejs/node/blob/c1442ec9c45cecf156fb32ad2174c4aceef37de7/doc/abi_version_registry.json#L9) and suggests that your tests were installed with/compiled for the version of Node.js that Electron provides.

Thank you so much! But I’m wondering, if I use nodegit in Electron it works. Isn’t that suspicious?

Not really. Something in nodegit is an addon and when those are installed they need to be compiled to match the application binary interface (ABI) for the version of Node.js (this is the where NODE_MODULE_VERSION comes in). The ABI is a combination of Node.js and V8 APIs. Electron has a different NODE_MODULE_VERSION because it uses a different version of V8. When the addon is loaded by Node.js a check is made that the addon was compiled against the same ABI as the Node.js about to run it.

In your broken case the addon was compiled for Electron but you were trying to run it on (non-Electron) Node.js 14.15.0. If used in Electron then you are running with Electron's version of Node.js and the ABI's will match.

richardlau avatar Nov 12 '20 17:11 richardlau

Thanks, what you described to me makes absolutely sense to me! But in the log file of nodegit I can see it got compiled with version 83.

In my example repository, I have a dependency to electron, but if I remove that and redo the installation, it still fails with the same error. Which shows me, that electron is not part of the problem. Could you give me a hint, how I can debug this?

MMcKester avatar Nov 12 '20 18:11 MMcKester

How are you doing the installation? If you're running from the command line check your PATH environment to see if Electron's version of Node.js is on the path.

richardlau avatar Nov 12 '20 18:11 richardlau

I can confirm it’s node 14.15.0. Please see the instructions below:

% node --version 14.15.0 % npm install % npm run ava ... error

Can you reproduce this? Or does it work with you? But as I said, it even compiled it with Version 83, that’s what I see in the log. Only during run time it fails Incomes up with a complete different version 82. And I use the process monitor from SysIntermals to confirm that the same version of node is used.

MMcKester avatar Nov 12 '20 19:11 MMcKester

Sorry, I've never used Electron before.

richardlau avatar Nov 12 '20 19:11 richardlau

FWIW this is what I get with a clean checkout of https://github.com/Githubber2021/node_module_version-issue and Node.js 14.15.0:

PS C:\Users\rlau\sandbox\github\node_module_version-issue> dir


    Directory: C:\Users\rlau\sandbox\github\node_module_version-issue


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        12/11/2020     20:41             13 .gitignore
-a----        12/11/2020     20:41         188924 package-lock.json
-a----        12/11/2020     20:41            852 package.json
-a----        12/11/2020     20:41             47 README.md


PS C:\Users\rlau\sandbox\github\node_module_version-issue> node --version
v14.15.0
PS C:\Users\rlau\sandbox\github\node_module_version-issue> npm --version
6.14.8
PS C:\Users\rlau\sandbox\github\node_module_version-issue> npm install

> [email protected] install C:\Users\rlau\sandbox\github\node_module_version-issue\node_modules\nodegit
> node lifecycleScripts/preinstall && node lifecycleScripts/install

[nodegit] Running pre-install script
[nodegit] Running install script
node-pre-gyp
WARN Using request for node-pre-gyp https download
[nodegit] Success: "C:\Users\rlau\sandbox\github\node_module_version-issue\node_modules\nodegit\build\Release\nodegit.node" is installed via remote
[nodegit] Completed installation successfully.

> [email protected] postinstall C:\Users\rlau\sandbox\github\node_module_version-issue\node_modules\nodegit
> node lifecycleScripts/postinstall


> [email protected] postinstall C:\Users\rlau\sandbox\github\node_module_version-issue
> electron-builder install-app-deps

'electron-builder' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `electron-builder install-app-deps`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\rlau\AppData\Roaming\npm-cache\_logs\2020-11-12T20_50_55_646Z-debug.log
PS C:\Users\rlau\sandbox\github\node_module_version-issue> code .
PS C:\Users\rlau\sandbox\github\node_module_version-issue> npm run ava

> [email protected] ava C:\Users\rlau\sandbox\github\node_module_version-issue
> ava


  1 test passed
PS C:\Users\rlau\sandbox\github\node_module_version-issue>

richardlau avatar Nov 12 '20 21:11 richardlau

Thanks so much for your help! I think you pointed me to the right direction! I removed Electron but what I didn't think of was the Electron-builder itself, which builds the binary. I will still need to do some research because there are a few question marks left, but I think this is going into the right direction. I will keep you posted! :-) Thanks again

MMcKester avatar Nov 12 '20 21:11 MMcKester

@MMcKester any update on this?

preveen-stack avatar Sep 05 '23 08:09 preveen-stack

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar May 11 '24 01:05 github-actions[bot]

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Jun 10 '24 01:06 github-actions[bot]