jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
9.32k stars 259 forks source link

`mise install` fails to install missing `npm:...` package #2174

Closed xavdid closed 3 weeks ago

xavdid commented 4 months ago

Describe the bug

When the active configuration file lists an npm package that isn't installed, mise install fails with an error:

Error:
   0: failed to execute command: npm install -g tldr@3.4.0 --prefix /Users/david/.local/share/mise/installs/npm-tldr/3.4.0
   1: No such file or directory (os error 2)

Location:
   src/cmd.rs:242

Version:
   2024.5.21 macos-arm64 (2024-05-23)

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

To Reproduce

  1. In an empty directory, create the following config:
[tools]
"npm:tldr" = "latest"

[settings]
# needed for npm packages
experimental = true
  1. run mise install

Expected behavior

The npm package tldr is installed and the tldr command works.

mise doctor output

version: 2024.5.21 macos-arm64 (2024-05-23)
activated: yes
shims_on_path: no

build_info: 
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS
  Built: Thu, 23 May 2024 03:16:31 +0000
  Rust Version: rustc 1.78.0 (9b00956e5 2024-04-29) (Homebrew)
  Profile: release

shell: 
  /bin/zsh
  zsh 5.9 (x86_64-apple-darwin22.0)

dirs: 
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/Library/Caches/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files: 
  ~/.config/mise/config.toml
  ~/Desktop/tt/mise.toml

backends: 
  cargo
  core
  go
  npm
  pipx
  ubi

plugins: 
  bun     (core)
  deno    (core)
  elixir  https://github.com/mise-plugins/mise-elixir.git#7b06439
  erlang  (core)
  go      (core)
  java    (core)
  node    (core)
  python  (core)
  ruby    (core)
  zig     (core)

toolset: 
  npm:tldr@3.4.0        (missing)
  python@3.12.3         
  node@20.13.1          
  go@1.22.3             
  elixir@1.16.3-otp-26  
  npm:trash-cli@5.0.0   
  npm:epub-wordcount@2.1.2  
  npm:will-it-play@1.0.1  

env_vars: 
  MISE_SHELL=zsh

settings: 
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cargo_binstall = true
  color = true
  disable_default_shorthands = false
  disable_tools = []
  experimental = true
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  node_compile = false
  not_found_auto_install = true
  paranoid = false
  plugin_autoupdate_last_check_duration = "7d"
  python_default_packages_file = "/Users/david/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  raw = false
  trusted_config_paths = []
  quiet = false
  verbose = false
  yes = false
  ci = false
  debug = false
  trace = false
  log_level = "info"
  python_venv_auto_create = false

  [status]
  missing_tools = "always"
  show_env = false
  show_tools = false

No warnings found
No problems found

Additional context

I thought this was related to https://github.com/jdx/mise/issues/2154, but I see that was fixed (and released) and I can still reproduce.

Also weirdly, the command that's listed as failing (npm install -g tldr@3.4.0 --prefix /Users/david/.local/share/mise/installs/npm-tldr/3.4.0) works if run directly. I've confirmed the /Users/david/.local/share/mise/installs/npm-tldr directory exists, but is empty.

nuomi1 commented 4 months ago

Same as me.

risu729 commented 3 months ago

The same issue occurred for me with other backends, at least with cargo and ubi.

bellini666 commented 3 months ago

Also experiencing this with some specific npm libs

From this list https://github.com/bellini666/dotfiles/blob/master/mise/config.toml#L44, I'm experiencing issues with:

FelisNivalis commented 3 months ago

I have the same issue. And after looking into it, mise adds to PATH only the packages you pass as parameters, so if you do mise install npm:xxx npm:yyy, only the bin path to /mise/path/to/xxx and /mise/path/to/yyy will be included, but not /mise/path/to/npm. So you will see the error if you don't have a system version of npm.

A workaround is to add the mise shims dir in your PATH, or do mise install npm npm:xxx npm:yyy every time (even if you already installed and used npm with mise).

It would be nice to also improve the error message here, as it's misleading that people would interpret the error message as if the path is not found, but it actually says npm is not found!

xavdid commented 4 weeks ago

Looks like this is an issue across all experimental backends? Probable duplicates:

xavdid commented 4 weeks ago

Ok, I had some time for this today.

I think ultimately it comes down to the the ctx.ts.list_paths() not correctly including the deps (in this case, node):

https://github.com/jdx/mise/blob/6730416d39a8b95418670d9853e0cc1e4ad5cafc/src/backend/npm.rs#L73

Adding .envs(self.dependency_env()?) fixes the issue, but given that it affects so many of the experimental backends, there's probably a more central way to do this