tree-sitter / node-tree-sitter

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

Issue installing tree-sitter with pnpm #123

Open kevinkeckeis opened 1 year ago

kevinkeckeis commented 1 year ago

Issue installing tree-sitter with pnpm

When trying to install tree-sitter with pnpm install, the installation fails with an "ELIFECYCLE Command failed" error. Upon investigating, it appears that the installation script checks for a pre-built binary, which is not available for Linux systems. As a result, the script tries to build tree-sitter using node-gyp, which is not included as a dependency and is not installed on the system, causing the installation to fail.

The following error message is displayed when running pnpm install inside the node_modules/tree-sitter folder:

prebuild-install WARN install No prebuilt binaries found (target=18.14.0 runtime=node arch=x64 libc= platform=linux)
sh: 1: node-gyp: not found

I am not experienced with build systems, and was surprised that npm attempted to run the command and even fetch and install node-gyp if it was detected. I expected the installation script to either run without issues or return a proper error message indicating the missing dependency.

Possible Solutions/Workarounds:

Versions:

sogaiu commented 1 year ago

After writing the following I got the sense that cloning this repository and trying to use tree-sitter from within it isn't really an intended scenario. I'll leave the rest of the post here though as it may have some clues regarding various build / installation issues.

Old content follows.


I don't use pnpm but I just tested some installation-like steps using 16f7319c993e07a4b28afad354b80624237c6660 (note that's the latest commit on the "default" branch here as of this writing) with a number of Node.js / npm versions using nvm.

What I found is that success varied, depending on at least a few things.

First, I used --recursive when cloning the repository, so just git clone https://github.com/tree-sitter/node-tree-sitter didn't lead to successful builds [1].

Then, for the following versions of Node.js, npm install completes successfully:

npx tree-sitter dump-languages didn't work for v16.19.0 (though it did work for the other 2 versions), so although it appears building was successful for that version, that doesn't by itself seem sufficient for use (at least of the cli).

npm install didn't successfully complete here for the following versions:

As I understand it, npm is capable of using node-gyp (one it depends on / is bundled with) to handle the case of binding.gyp being in a project's repository -- i.e. this is without a project specifically having node-gyp as a dependency or devDependency. I may be wrong about this though -- it doesn't seem so straight-forward to get answers to these sorts of things unfortunately.

As some evidence in favor of the above idea though, according to this nicely buried piece of documentation:

If there is a binding.gyp file in the root of your package and you haven't defined your own install or preinstall scripts, npm will default the install command to compile using node-gyp.

That's for v6 of npm, but looking at the corresponding page for more recent versions one can see similar text.

Perhaps the code in 16f7319c993e07a4b28afad354b80624237c6660 of node-tree-sitter doesn't play so well with more recent versions of Node.js / npm.


[1] IIUC, there is a git submodule involved so that needs to be attended to appropriately I guess (possibly using git submodule subcommands like init and update if --recursive or other is not using during a clone).

davidluhr commented 1 year ago

I'm experiencing the same issue when trying npm install tree-sitter, both in Windows Subsystem for Linux 2 (which uses Ubuntu), and in MacOS.

WSL2 (Ubuntu) output: prebuild-install WARN install No prebuilt binaries found (target=19.7.0 runtime=node arch=x64 libc= platform=linux)

MacOS output: prebuild-install WARN install No prebuilt binaries found (target=19.7.0 runtime=node arch=x64 libc= platform=darwin)

I tried with older versions of Node and had the same issue. Not sure how to proceed.

sogaiu commented 1 year ago

I'm not sure I parse the errors you posted correctly, but the sense I get is that those are for node 19.7.0, which I didn't have any luck with (along with the 18 series).

It seems though that some people have had success with 18 (though not 19). Here is another report of some success with 18.

If it's practical for you to try with node 12.x or 14.y may be it's worth it? Or may be you tried and got errors? If so, would you mind sharing them?

It was unclear to me whether any of the 16 series would work either based on my own testing, but there is also a report here of lack of success on that front -- though at the end it seems another person may have resolved things.

sogaiu commented 1 year ago

This comment might be of interest if trying to get things working with Node.js 19.x.

verhovsky commented 1 year ago

https://github.com/pnpm/pnpm/issues/4347