tree-sitter / node-tree-sitter

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

"node_tree_sitter_runtime_binding.node is not a valid Win32 application." under windows when using node-tree-sitter in a VSCode extension #89

Closed Symbolk closed 3 years ago

Symbolk commented 3 years ago

Hi, I developed a VSCode extension to help developers handle merge conflicts, which depends on node-tree-sitter. Its name is SoManyConflicts, the source is open at https://github.com/Symbolk/somanyconflicts and the extension can be downloaded in VSCode Market.

Since node-tree-sitter is a native module and should be built on specific platform, the extension works fine for macOS (which it is original built upon) but fails to activate on Windows, with the error message:

[2021-06-15 14:20:20.236] [exthost] [error] Activating extension Symbolk.somanyconflicts failed due to an error:
[2021-06-15 14:20:20.236] [exthost] [error] Error: \\?\c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node is not a valid Win32 application.
\\?\c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1185:18)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1846)
    at Module.load (internal/modules/cjs/loader.js:982:32)
    at Module._load (internal/modules/cjs/loader.js:823:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
    at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
    at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at v (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:698)
    at Object.<anonymous> (c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\node_modules\tree-sitter\index.js:3:13)
    at Module.u._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:1315)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
    at Module.load (internal/modules/cjs/loader.js:982:32)
    at Module._load (internal/modules/cjs/loader.js:823:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
    at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
    at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at v (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:698)
    at Object.<anonymous> (c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\out\SoManyConflicts.js:20:20)
    at Module.u._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:1315)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
    at Module.load (internal/modules/cjs/loader.js:982:32)
    at Module._load (internal/modules/cjs/loader.js:823:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
    at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
    at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at v (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:698)
    at Object.<anonymous> (c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\out\extension.js:18:27)
    at Module.u._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:1315)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
    at Module.load (internal/modules/cjs/loader.js:982:32)
    at Module._load (internal/modules/cjs/loader.js:823:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
    at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
    at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Function.t [as __$__nodeRequire] (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:5:101)
    at f._loadCommonJSModule (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:25948)
    at f._doActivateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:89:12599)
    at f._activateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:89:11658)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

I and trying to rebuild it under Windows but encountered lots of problems with windows-build-tools, but once it works, it means that my users have to rebuild the extension from source to install it. Therefore, I am wondering:

  1. For the tree-sitter side, it there any way to avoid rebuilding from source for installation?
  2. For the VSCode extension side, whether it is feasible to upload a vsix file targeting at different platforms for one extension? And
sogaiu commented 3 years ago

Perhaps this is already known, but FWIW, it was at one point possible to build vscode extensions that make use of wasm bits. An advantage of such an approach is that there is only one build.

IIRC, that ends up using web-tree-sitter instead of node-tree-sitter though.

Here is an example (deprecated) extension that did that: https://github.com/georgewfraser/vscode-tree-sitter

razzeee commented 3 years ago

I'm still doing that here https://github.com/elm-tooling/elm-language-server

For your question on 2. that's not possible, see https://github.com/microsoft/vscode/issues/23251

However, some extensions are shipping binaries, by having the client download them depending on the OS/ARCH

Symbolk commented 3 years ago

Thanks, by rebuilding it under Windows with windows-build-tool, now I am able to install and run it under windows vscode, although other errors follow.

For now I decide to release the different versions from different platforms on GitHub. Let's see if there are better solutions.