开发 vscode 扩展时针对不同 NODE_MODULE_VERSION 编译的模块
我尝试在我的 vscode 扩展中使用节点的 tree-sitter 包,但出现以下错误:
激活扩展“扩展名称”失败:模块“.../node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node” 使用不同的 Node.js 版本进行编译 NODE_MODULE_VERSION 93。此版本的 Node.js 需要 NODE_MODULE_VERSION 89.请尝试重新编译或重新安装 模块(例如,使用
npm rebuild
或npm install
)..
据我了解,NODE_MODULE_VERSION是节点ABI的版本。然而,我什至在官方网站。
我尝试过:
- 删除node_modules文件夹并重新安装软件包。
- 从顶层目录运行
npmbuildtree-sitter --update-binary
。 - 使用
node_modules/tree-sitter< 中的
node-gyprebuild
和node-gyprebuild --target=(my node version)
重建 tree-sitter 包/代码> 目录。 - 使用 nvm 切换节点版本。
这些都没有帮助。据我了解,更改节点版本不会有帮助,因为当我尝试
console.log(process.version); 时我确认了// v14.16.0
console.log(process.versions.modules); // 89
无论我使用哪个节点版本,这都会给出相同的输出。我还尝试使用该节点版本 node-gyprebuild --target=14.16.0
重建 tree-sitter 包,但我得到了相同的错误,但是这次它说该模块是使用 NODE_MODULE_VERSION 编译的83,这与节点网站的说法一致。
我该如何解决这个错误? 任何帮助表示赞赏。
I'm trying to use node's tree-sitter package in my vscode extension, but I get the following error:
Activating extension 'extension name' failed: The module '.../node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 93. This version of Node.js requires
NODE_MODULE_VERSION 89. Please try re-compiling or re-installing
the module (for instance, usingnpm rebuild
ornpm install
)..
From what I understand, the NODE_MODULE_VERSION is the version of node's ABI. However, I couldn't even find a release of node that has NODE_MODULE_VERSION 89 in the official website.
What I've tried:
- Deleting the node_modules folder and reinstalling the packages.
- Running
npm rebuild tree-sitter --update-binary
from the top directory. - Rebuilding the tree-sitter package with
node-gyp rebuild
andnode-gyp rebuild --target=(my node version)
from thenode_modules/tree-sitter
directory. - Switching node versions using nvm.
None of that helped. I understand from here that changing node versions won't help, as I confirmed when I tried
console.log(process.version); // v14.16.0
console.log(process.versions.modules); // 89
This gave the same output no matter which node version I used. I also tried rebuilding the tree-sitter package using that node version node-gyp rebuild --target=14.16.0
, but I get the same error, however this time it says the module was compiled using NODE_MODULE_VERSION 83, which is consistent with what node's site says.
How do I resolve this error?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我怀疑的那样,vscode扩展使用的节点ABI版本是vscode内部电子使用的ABI版本。 根据此来源
这解释了为什么我在节点站点中找不到 NODE_MODULE_VERSION 89 。
接下来,我检查了我的 vscode 版本使用的电子版本。为此,我简单地检查了 vscode 附带的 package.json (在 Linux 上为
/usr/lib/code/package.json
,我猜它位于 Windows 上安装 vscode 的文件夹内)。接下来,按照 Electron 站点的说明,使用包
electron-rebuild
重建模块。要指定目标版本,只需运行./node_modules/.bin/electron-rebuild -v [version]
但是,我没有这方面的源代码,但似乎 tree-sitter 目前不支持更新的版本版本的电子,因此构建失败。这似乎是因为 V8 的 API 发生了变化(据此)。
作者在此处链接了他的解决方案。我复制了他的更改并且构建成功了。
请注意,我必须用新建的节点插件替换现有的节点插件。
As I suspected, the version of node ABI used by vscode extensions is the ABI version used by vscode's internal electron. According to this source
This explains why I couldn't find NODE_MODULE_VERSION 89 in node's site.
Next, I checked what version of electron my build of vscode uses. To do this, I simply checked the package.json that came with vscode (
/usr/lib/code/package.json
on linux, I guess that it is inside the folder vscode is installed on on windows).Next, following the instructions from electron's site, rebuild the module using the package
electron-rebuild
. To specify a target version, simply run./node_modules/.bin/electron-rebuild -v [version]
However, I have no source for this but it seems that tree-sitter does not currently support newer versions of electron, so the build fails. This seems to be because of a change in V8's API (according to this).
The author linked his solution here. I copied his changes and the build succeeded.
Note that I had to replace the existing node addon with the newly built one.