tj / n

Node version management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Broke npm after install n

IBlasterus opened this issue · comments

Bug Report

Broke npm after install n

Summary

Broke npm after install n

Steps to Reproduce

sudo npm i -g n
sudo n lts
npm -v

Error:
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'semver'

Expected Behaviour

npm -v
6.14.4

Actual Behaviour

Error:
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'semver'

Other Information

Configuration Details

$ n --version
v8.2.0

$ command -v node
/usr/local/bin/node

$ node -p process.platform
linux

By default installing Node.js using n installs both node and npm. So you should have npm 8.11.0 after installing lts.

My guess is that the previous version of npm is in a different location than the fresh install and is the one being run. I don't know why it broke though!

What do these show:

command -v npm
echo $PATH

command -v npm
/usr/bin/npm

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Strange, because n should have installed npm into /usr/local/bin which is earlier in the path.

One simple check, try running npm again from a new shell or terminal window in case your current shell has not caught up with the changes. (Or run rehash if your shell supports that.)

You could also run n doctor, which picks up some setup problems.

Would you please remove the cached version and do a reinstall of lts and include the progress messages. Like this:

$ sudo n rm lts
$ sudo n lts
  installing : node-v16.15.1
       mkdir : /usr/local/n/versions/node/16.15.1
       fetch : https://nodejs.org/dist/v16.15.1/node-v16.15.1-darwin-x64.tar.xz
     copying : node/16.15.1
   installed : v16.15.1 (with npm 8.11.0)

Sorry, I'm already installed latest LTS version by this way:
https://techviewleo.com/how-to-install-nodejs-in-linux-mint/
It's work for me now.

Ok, if you have problem again in future feel free to open another issue.

I just encountered this issue on Ubuntu 22.04 on AWS (but oddly enough not on my Ubuntu 22.04 local VM). The solution was to add PATH=/usr/local/n/versions/node/18.15.0/bin:$PATH (assuming 18.15.0) to the end of my .profile (or export PATH=/usr/local/n/versions/node/18.15.0/bin:$PATH for the current session of course). Not sure what the difference is.