使用ava时错误的NODE_MODULE_VERSION [英] Incorrect NODE_MODULE_VERSION when using ava

查看:145
本文介绍了使用ava时错误的NODE_MODULE_VERSION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个使用 nodegit 的Electron应用程序.对于我的测试部分,我将 ava 与Spectron结合使用来测试我的应用程序.我所有的测试工作正常-包括在我的应用中使用 nodegit 的功能.

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.

除了上述测试之外,我还制作了一个纯 non-Electron 测试文件,可以直接在其中导入nodegit.

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';

立即通过 ava 执行此测试,返回以下内容:

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)

82版究竟从何而来?我只安装了 nodejs 14.15.0 ,该版本按预期使用了 83 版本.为什么 node 认为该版本与我的应用中实际工作的版本不匹配?这是我的 package.json 的样子:

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"
    ]
  },

我自己构建了 nodegit ,并且在 config.gypi 文件中甚至引用了:

I built nodegit myself and in the config.gypi file it even refers to:

    "node_module_version": 83,

我做了一个超级简单的可重现示例: https://github.com/Githubber2021/node_module_version-issue

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

有人能解释这个错误或82版本的来源吗?

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

推荐答案

这可能是两件事之一:

  1. 您正在加载的本机依赖性通过 prebuild 提供预构建的二进制文件-可能就是这种情况
  2. 您正在加载的本机依赖项将作为源代码下载,并由您自己来构建二进制文件.
  1. The native dependency you're loading provides prebuilt binaries via prebuild -- This is probably the case
  2. The native dependency you're loading is downloaded as source code and building the binary is up to you.

根据nodegit的自述文件,

According to nodegit's README,

"NodeGit可以在大多数系统中直接使用,而无需任何本地依赖项."

"NodeGit will work on most systems out-of-the-box without any native dependencies."

但是看起来您至少需要 nodegit@0.27.x 才能从使用节点14获得预构建的二进制文件.

But it looks like you need at minimum nodegit@0.27.x to get prebuilt binaries from use Node 14. Source

因此,您看到的 82 来自预编译二进制文件针对的ABI版本.由于您已经在使用 nodegit@0.27.x ,因此以某种方式最终使用了错误的ABI的预编译二进制文件.

So the 82 you're seeing comes from the ABI version that the prebuilt binary was compiled against. Since you're already using nodegit@0.27.x, then somehow you've ended up with the prebuilt binaries for the wrong ABI.

这是我使用的一个回购,列出了不同版本的所有二进制文件,因此您可以看到这种情况如何发生:

Here's a repo I use that lists out all the various binaries for different versions, so you can see how this might happen: https://github.com/lovell/sharp/tree/v0.25.3

我在Electron中进行开发,对于Electron,我使用类似这样的命令来获取正确版本的Electron来对它运行 npm rebuild .

I develop in Electron and for Electron I use a command like this to get the correct version of Electron to run npm rebuild against.

npm rebuild --runtime=electron --target=8.5.3 --disturl=https://atom.io/download/atom-shell

我确切地不知道对于普通节点是什么,但是请让我知道这是否会使您更接近,如果可以的话,我会找到可以找到的东西.

I don't know exactly what the equivalent is for plain node, but let me know if this gets you closer and if so I'll see what I can find.

这篇关于使用ava时错误的NODE_MODULE_VERSION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆