asdf-nodejs
asdf-nodejs copied to clipboard
Support global NPM installs between Node versions
Today I upgraded from Node 6.7 to 6.8, and now my global NPM installations all say something like:
No such command in 6.8.0 of nodejs
There's no reason that my NPM modules need to be limited to the Node version that installed them. Can the commands they install not stay intact? I thought a asdf reshim nodejs
would do it but apparently not. Am I missing something?
I also have something similar, but it's clean install. I got this error
Already did reshim
but the problem still persists.
Another screenshot related to comment above. This one is not about npm, but about the node itself.
I'm sorry if this is the problem from my configuration, I'm pretty new to this stuff.
Ah, my bad. Actually, I'm at fault here. I'm cloning the asdf-vm master
current HEAD
instead of the branch v0.2.0
. I'm sorry.
I'm actually having this same issue. When I upgrade NPM on one version of node v4.4.5 and npm@3
, and then swap node versions v6.1.0
, then swap back, somehow the npm version in the v.4.4.5
install goes back to v2.15.5
.
Having the same issue here. Any help?
I'm having a similar problem.
In my latest nodejs
version (8.6.0) npm
works fine, but in every other version I'm using (6.11.3, 8.4.0) I'm getting a No such command in 8.4.0 of nodejs
.
A reshim
didn't do anything.
Having the same issue NPM "command not found" after installing with asdf
I am unable to use global packages on older versions of nodejs same as @stefanfrede reshim does nothing
@ndarilek is this still an issue?
Hmm... just a question, does asdf support migrating global packages into the new nodejs installation, such us: nvm install node --reinstall-packages-from=node
in nvm
. For example: I installed eslint
globally in node 8.15.1, then I install the node 12.14.1 and set node 12.14.1 as current global version. Currently, the eslint
bin only exists on 8.15.1, but not on the new 12.14.1... :bowing_man:
cc: @Stratus3D. Here's my result.
asdf-vm: v0.7.8-4a3e3d6
asdf-nodejs: cd8dc32e82507a229fe90c0b01d1089a3ac6844c
nodejs: v12.16.2
Plan/Execution Step
I have create-next-app
global cli in nodejs v12.16.2 LTS. Now, I want to upgrade my nodejs to v12.18.3 LTS. After that, I expect that the create-next-app
still available while I have upgraded the node to v12.18.3 LTS.
- Check
node --version
->v12.16.2
. - Install
create-next-app
as global cli usingnpm install -g create-next-app
. - Run
asdf reshim nodejs
. - Check
create-next-app
has bee listed usingnpm ls -g --depth=0
. - Update asdf-nodejs plugin using
asdf plugin update nodejs
. - Install nodejs 12.18.3 LTS by using
NODEJS_CHECK_SIGNATURES=no asdf install nodejs 12.18.3
(I need to bypass the signature checking since my gpg setting doesn't allow weak digest). - Ensure nodejs 12.18.3 has been installed by using
asdf list nodejs | grep 12.18.3
. - Change global nodejs version to 12.18.3 by using
asdf global nodejs 12.18.3
. - Run reshim again
asdf reshim nodejs
. - Ensure nodejs has been upgrade by using
node --version
->v12.18.3
. - Check
create-next-app
cli is still available while upgrading to nodejs 12.18.3 by usingnpm ls -g --depth=0
.
Expected Behavior
create-next-app
is still available in node v12.18.3.
Actual Behavior
create-next-app
is not available in node v12.18.3.
➜ npm ls -g --depth=0
/home/jeffryangtoni/.asdf/installs/nodejs/12.18.3/.npm/lib
└── (empty)
Probably asdf need to support this feature from nvm
? nvm install node --reinstall-packages-from=node
:bow:
@Stratus3D This is definitely an ongoing issue. With Homebrew, the path to global node modules doesn't change between updates, as it's kept in a separate location (/usr/local/lib/node_modules
). But in asdf, the path is something like:
/Users/my_user/.asdf/installs/nodejs/14.11.0/.npm/lib/node_modules
Since it's namespaced by the version number, we lose access to globally installed modules on every update of node.
There are some traps around sharing global installs between node versions, mostly incompatibilities. Some packages only support specific node versions. Others need to be built against a specific version (node-sass is famous for doing it for maximum performance).
If you ever share the packages between versions, you need to be aware that depending on the context you are in, in a project with a different node version than your global installation for example, your global commands might not work, and you will get errors, npm
itself is a globally installed package that needs specific node versions and might not work in different contexts.
As of now, you can have a command in installed all versions by setting up default npm packages that are installed automatically after every asdf install nodejs $version
. A nice oneliner for installing a global command in every version is:
npm_install_all_versions() {
for pkg; do
asdf list nodejs | xargs -n1 -I{} env ASDF_NODEJS_VERSION="{}" npm install -g "$pkg"
done
}
npm_install_all_versions npm typescript tldr
After making that clear, I totally think that is possible to have global and version-specific installations utilizing of path priority and the prefix npm config that might ease this problem. I will look into something this week