tree-sitter / node-tree-sitter

Node.js bindings for tree-sitter
https://www.npmjs.com/package/tree-sitter
MIT License
659 stars 115 forks source link

The module 'l\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 118. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`) #188

Closed suraiya-syed closed 4 months ago

suraiya-syed commented 9 months ago

I am trying to use tree-sitter parser library in am VS Code extension. I am able to build tree-sitter using command "npm run rebuild". Unable to run(F5) the extension.

Import statement: const Parser = require('tree-sitter')

Error: Uncaught Error Error: The module 'l\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 118. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install). at func (node:electron/js2c/asar_bundle:2:2131) at (node:internal/modules/cjs/loader:1403:18) at func (node:electron/js2c/asar_bundle:2:2131) at (node:internal/modules/cjs/loader:1173:32) at (node:internal/modules/cjs/loader:1014:12) at (node:electron/js2c/asar_bundle:2:13327) at (node:internal/modules/cjs/loader:1197:19) at require (node:internal/modules/cjs/helpers:121:18) at (file:../node_modules/tree-sitter/index.js:3:13) at (node:internal/modules/cjs/loader:1318:14) at (node:internal/modules/cjs/loader:1373:10) at (node:internal/modules/cjs/loader:1173:32) at (node:internal/modules/cjs/loader:1014:12) at (node:electron/js2c/asar_bundle:2:13327) at (node:internal/modules/cjs/loader:1197:19) at require (node:internal/modules/cjs/helpers:121:18) at (file:../server/out/server.js:12:16) at (node:internal/modules/cjs/loader:1318:14) at (node:internal/modules/cjs/loader:1373:10) at (node:internal/modules/cjs/loader:1173:32) at (node:internal/modules/cjs/loader:1014:12) at (node:electron/js2c/asar_bundle:2:13327) at executeUserEntryPoint (node:internal/modules/run_main:96:12) at (node:internal/main/run_main_module:23:47)

Already followed https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules. 
verhovsky commented 9 months ago

your npm run rebuild command needs to match the Electron version of your VS Code. Open VS Code, press in the top left About Visual Studio Code, copy the "Electron: 27.2.3" (or whatever) string then change the rebuild command in package.json to

    "rebuild": "electron-rebuild --version 27.2.3"
gaspardruan commented 9 months ago

I have the same problem when importing tree-sitter in a simple electron template, then I rebuild successfully as above said. But the app can't start owing to the error:

[9776:0223/013812.099:ERROR:node_bindings.cc(154)] Fatal error in V8: v8_ArrayBuffer_NewBackingStore When the V8 Sandbox is enabled, ArrayBuffer backing stores must be allocated inside the sandbox address space. Please use an appropriate ArrayBuffer::Allocator to allocate these buffers, or disable the sandbox.
[9776:0223/013812.099:ERROR:crashpad_client_win.cc(863)] not connected

I found the description about the problem in electron document:

How will I know if my app is impacted by this change? Attempting to wrap external memory with an ArrayBuffer will crash at runtime in Electron 20+. If you don't use any native Node modules in your app, you're safe—there's no way to trigger this crash from pure JS. This change only affects native Node modules which allocate memory outside of the V8 heap (e.g. using malloc or new) and then wrap the external memory with an ArrayBuffer. This is a fairly rare use case, but some modules do use this technique, and such modules will need to be refactored in order to be compatible with Electron 20+.

I also read the #177 , but is seems that the problem still occurs.

segevfiner commented 8 months ago

The latest version is Node-API based which should work in electron, but the grammars still need to also be regenerated to use Node-API.