1

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, using npm rebuild or npm 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 and node-gyp rebuild --target=(my node version) from the node_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.

Kobi Mizrachi
  • 123
  • 1
  • 1
  • 8

1 Answers1

2

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

Native Node.js modules are supported by Electron, but since Electron has a different application binary interface (ABI) from a given Node.js binary (due to differences such as using Chromium's BoringSSL instead of OpenSSL), the native modules you use will need to be recompiled for Electron...

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.

Kobi Mizrachi
  • 123
  • 1
  • 1
  • 8