williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.86k stars 277 forks source link

Npm (installed through Volta) can't be found #879

Open joyofirony opened 1 year ago

joyofirony commented 1 year ago

I've searched open issues for similar requests

Yes

I've recently downloaded the latest plugin version of mason.nvim

Problem description

After installing the mason.nvim plugin, no LSP server relying on NPM could not be installed even though both Node and Npm executables can be found in %PATH%:

﬌ node -v v18.12.1

﬌ npm -v 8.19.2

﬌ Get-Command npm

CommandType Name Version Source


Application npm.exe 0.0.0.0 XXX\volta\current\appdata\bin\npm.exe

I used scoop to install volta, and then installed node/npm through volta.

After checking Issue #781, it seems that mason only checks the npm executable through npm.cmd or npm and does not consider npm.exe as a valid candidate (volta installed only .exe files, no .cmd nor .ps1).

I updated the spawn.lua file as below:

---@alias JobSpawn table<string, async fun(opts: SpawnArgs): Result>
---@type JobSpawn
local spawn = {
    _aliases = {
        npm = platform.is.win and "npm.exe" or "npm.cmd" or "npm",
        gem = platform.is.win and "gem.cmd" or "gem",
        composer = platform.is.win and "composer.bat" or "composer",
        gradlew = platform.is.win and "gradlew.bat" or "gradlew",
        -- for hererocks installations
        luarocks = (platform.is.win and vim.fn.executable "luarocks.bat" == 1) and "luarocks.bat" or "luarocks",
        rebar3 = platform.is.win and "rebar3.cmd" or "rebar3",
    },
    _flatten_cmd_args = _.compose(_.filter(_.complement(_.equals(vim.NIL))), _.flatten),
} 

and managed to get npm.exe recognized by mason:

mason.nvim report

  • OK: neovim version >= 0.7.0
  • OK: Go: go version go1.19.4 windows/amd64
  • WARNING: cargo: not available
  • WARNING: luarocks: not available
  • WARNING: Ruby: not available
  • WARNING: RubyGem: not available
  • WARNING: Composer: not available
  • WARNING: PHP: not available
  • OK: npm: 8.19.2
  • OK: node: v18.12.1

Expected behavior

Npm-based LSP servers shoud install successfully

Affected packages

Any that uses npm

Mason output

Failed
    ◍ typescript-language-server
      ▶ # [2/2] spawn: npm.cmd failed with exit code - and signal -. npm.cmd is not executable

Installation log

[INFO  09/01/2023 15:06:22] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:120: Executing installer for Package(name=gopls)
[INFO  09/01/2023 15:07:10] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:152: Installation succeeded for Package(name=gopls)
[INFO  09/01/2023 15:07:23] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:120: Executing installer for Package(name=terraform-ls)
[INFO  09/01/2023 15:07:33] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:152: Installation succeeded for Package(name=terraform-ls)
[INFO  09/01/2023 15:08:51] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:120: Executing installer for Package(name=jdtls)
[INFO  09/01/2023 15:09:22] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:152: Installation succeeded for Package(name=jdtls)
[INFO  09/01/2023 16:11:59] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:120: Executing installer for Package(name=typescript-language-server)
[ERROR 09/01/2023 16:11:59] ...l\nvim-data\mason.nvim/lua/mason-core/installer/init.lua:159: Installation failed for Package(name=typescript-language-server) error=spawn: npm.cmd failed with exit code - and signal -. npm.cmd is not executable

Neovim version (>= 0.7)

NVIM v0.8.2 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compilé par runneradmin@fv-az28-353

Operating system/version

Windows 11

Healthcheck

mason: require("mason.health").check()
========================================================================
## mason.nvim report
  - OK: neovim version >= 0.7.0
  - OK: **Go**: `go version go1.19.4 windows/amd64`
  - WARNING: **cargo**: not available
  - WARNING: **luarocks**: not available
  - WARNING: **Ruby**: not available
  - WARNING: **RubyGem**: not available
  - WARNING: **Composer**: not available
  - WARNING: **PHP**: not available
  - ERROR: **npm**: not available
  - OK: **node**: `v18.12.1`
  - WARNING: **python3**: not available
  - WARNING: **pip3**: not available
  - OK: **javac**: `javac 17.0.5`
  - OK: **java**: `java version "17.0.5" 2022-10-18 LTS`
  - WARNING: **julia**: not available
  - ERROR: **wget**: not available
  - OK: **curl**: `curl 7.83.1 (Windows) libcurl/7.83.1 Schannel`
  - WARNING: **gzip**: not available
  - OK: **tar**: `bsdtar 3.5.2 - libarchive 3.5.2 zlib/1.2.5.f-ipp bz2lib/1.0.6 `
  - OK: **pwsh**: `7.3.1 Microsoft Windows 10.0.22621 Win32NT`
  - OK: **python**: `Python 3.10.8`
  - OK: **pip**: `pip 22.3.1 from <REDACTED>\lib\site-packages\pip (python 3.10)`
  - OK: **7z**: `7-Zip 22.01 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15`
  - OK: **JAVA_HOME**: `java version "17.0.5" 2022-10-18 LTS`
  - OK: GitHub API rate limit. Used: 0. Remaining: 60. Limit: 60. Reset: 09/01/2023 16:52:17.

Screenshots

No response

musjj commented 1 year ago

Can't we just add an option to specify the executable via the setup function? I'm also having problems getting mason to detect my pyenv-win path under MSYS2. neovim/neovim#21175 doesn't help either, because it only works if your shell is pwsh or cmd. I'm currently using this hack, which works for for python:

vim.g.python3_host_prog = "python.bat"
mehalter commented 1 year ago

I also would like the ability to specify the executable paths if possible. I use lazy loading for loading npm/nvm/node and even though I can run npm at the command line, Mason isn't able to detect that it's there.

JonasBa commented 5 months ago

I have a similar issue when attempting to install the typescript lsp, though in my case it seems to fail to resolve node

 Failed (1)
                   ◍ typescript-language-server
                     ▼ Displaying full log
                       Volta error: Node is not available.

                       To run any Node command, first set a default version using `volta install node`
                       Error details written to /Users/jonasbadalic/code/sentry/.devenv/bin/volta-home/log/volta-error-2024-05-31_17_05_06.
                       spawn: npm failed with exit code 126 and signal 0.

Checkhealth for mason.nvim shows this error.

OK node: `v20.13.1`