mise
mise copied to clipboard
Changing NPM version
Describe the bug I am unable to change my npm version when node@14 is installed using rtx.
To Reproduce
rtx install node@14
rtx use node@14
npm install -g [email protected]
Fails with:
npm ERR! code EEXIST
npm ERR! path <REDACTED>/.local/share/rtx/installs/node/14.21.1/bin/npm
npm ERR! Refusing to delete <REDACTED>/.local/share/rtx/installs/node/14.21.1/bin/npm: is outside <REDACTED>/.local/share/rtx/installs/node/14.21.1/lib/node_modules/npm and not a link
npm ERR! File exists: <REDACTED>/.local/share/rtx/installs/node/14.21.1/bin/npm
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! <REDACTED>/.npm/_logs/2023-08-08T20_48_05_098Z-debug.log
Expected behavior
nvm install 14
nvm use 14
npm install -g [email protected]
Succeeds with:
<REDACTED>/.nvm/versions/node/v14.21.3/bin/npx -> <REDACTED>/.nvm/versions/node/v14.21.3/lib/node_modules/npm/bin/npx-cli.js
<REDACTED>/.nvm/versions/node/v14.21.3/bin/npm -> <REDACTED>/.nvm/versions/node/v14.21.3/lib/node_modules/npm/bin/npm-cli.js
+ [email protected]
added 93 packages from 28 contributors, removed 320 packages and updated 138 packages in 3.818s
rtx doctor
output
rtx version:
1.35.8 linux-x64 (3d305dc 2023-08-01)
build:
Target: x86_64-unknown-linux-gnu
Features: DEFAULT, NATIVE_TLS, OPENSSL
Built: Tue, 01 Aug 2023 19:04:00 +0000
Rust Version: rustc 1.71.0 (8ede3aae2 2023-07-12)
Profile: release
shell:
/usr/bin/bash
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
rtx data directory:
<REDACTED>/.local/share/rtx
rtx environment variables:
RTX_SHELL=bash
settings:
{"always_keep_download": "false", "always_keep_install": "false", "asdf_compat": "false", "disable_default_shorthands": "false", "disable_tools": "[]", "experimental": "false", "jobs": "4", "legacy_version_file": "true", "legacy_version_file_disable_tools": "[]", "log_level": "INFO", "missing_runtime_behavior": "warn", "plugin_autoupdate_last_check_duration": "10080", "raw": "false", "trusted_config_paths": "[]", "verbose": "false"}
config files:
<REDACTED>/.config/rtx/config.toml
<REDACTED>/projects/.rtx.toml
plugins:
aws-vault https://github.com/karancode/asdf-aws-vault.git#678cacf
go (core)
java (core)
node (core)
python (core)
ruby (core)
terraform https://github.com/asdf-community/asdf-hashicorp.git#c44c314
toolset:
node@14, [email protected], aws-vault@latest
No problems found
Additional context Only appears to take place with node@14; I can change the npm version fine with the latest node.
interesting bug, at first, I suppose it was issue about npm and node compatiblity. but when I download node14.tar.gz from nodejs.org then extract and npm i -g [email protected]
, it works as expected. then I suppose maybe it was issue about how nodenv install nodejs, so I also tried nodenv and nodebuild, npm 9.2.0 can be installed on node v14.23.1 too.
It's likely the npm shim is causing this. As a workaround, you can probably remove the shim and make it a symlink like it normally is.
We could probably fix this by not creating the shim at all for node <=14.
This is an EOL version of node though so it's low priority for me to fix.
Hi @jdxcode, may i ask something? I'm trying to figure it out.
you said shims cause problems here. but why use shims for node.
I tried to comment out this line, and build a new version. then to install nodejs 14 16 18, and try to update npm to latest version, install some npm packages with npm i -g
, it works well.
so what is this script for?
It's likely the npm shim is causing this. As a workaround, you can probably remove the shim and make it a symlink like it normally is.
Took me a sec to figure out what that meant, so leaving this here for posterity:
rm ~/.local/share/rtx/installs/node/14.21.1/bin/npm
ln -s ~/.local/share/rtx/installs/node/14.21.1/lib/node_modules/npm/bin/npm-cli.js ~/.local/share/rtx/installs/node/14.21.1/bin/npm
I can now update npm successfully. Thanks for the help!
This is an EOL version of node though so it's low priority for me to fix.
Fair enough, although I agree with @dfang that I was surprised that shims were being used based on the portion of the readme referenced, so even if fixing this issue for node 14 isn't a priority, maybe adding more detail to the readme could be on the radar?
the npm shim is used to automatically execute rtx reshim
when installing npm packages. This shim lives in ~/.local/share/installs/node/___/bin/npm
, rtx shims in ~/.local/share/rtx/shims
are not the same thing.
but echo $PATH | grep .local/share/rtx/shims
outputs nothing, I still don't understand what are shims for?
I have a similar issue with mise
:
λ eval "$(mise activate zsh)"
λ mise use -g node@lts
λ npm -v
10.5.0
λ npm i -g npm@latest
# ... (installs npm v10.5.2)
reshimming mise lts...
λ mise x -- npm i -g npm@latest
# ... (same install success followed by reshim message)
λ mise x node@20 -- npm i -g npm@latest
# same again
λ mise settings set experimental true
λ mise use -g npm:npm@latest
λ npm -v
10.5.0
It seems whichever I try, npm
refuses to budge. I wonder if there's a conflict as I have env vars set in .zshenv
:
#.zshenv
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc
export NVM_DIR="$XDG_DATA_HOME"/nvm
alias yarn=yarn --use-yarnrc "$XDG_CONFIG_HOME"/yarn/config
if type mise &> /dev/null; then
if [[ -t 0 ]]; then # terminal has stdin i.e. interactive
shell_name="$(echo -n "$SHELL" | sed 's>.*/>>')"
eval "$(mise activate "$shell_name")"
else
eval "$(mise activate --shims)"
fi
fi
I use those env vars to try and keep dotfiles out of $SHOME
as much as possible, but I'll try removing them to see if it helps.
Update: Removing the NPM_CONFIG_USERCONFIG
env var (and thus the conflicting paths config held within) fixed this issue for me. npm started creating $HOME/.npm
again, but on checking, it just contained cache files. So, I set NPM_CONFIG_CACHE="$XDG_CACHE_HOME"/npm
and all is well in the world (well, at least as far as my mise/npm config goes)