3

I'm trying to update my ancient npm 3.5.2 that is running in the Windows Subsystem for Linux on my Windows 10 to the latest version.

The command I'm running is as follows:

sudo npm install -g npm@latest

However, it fails and all I'm getting is the following output:

WARN engine npm@7.20.5: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
/usr/local/lib
└── (empty)
sudo apt install wsl
npm ERR! Linux 5.10.16.3-microsoft-standard-WSL2
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "npm@latest"atest
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552' -> '/usr/local/lib/node_modules/npm/node_modules/@npmcli/ci-detect'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552' -> '/usr/local/lib/node_modules/npm/node_modules/@npmcli/ci-detect'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /mnt/d/Summbit/Humanatomy.Web/npm-debug.log
npm ERR! code 1

I'm clueless what npm is trying to tell me. Does anyone know what is going on here?

ackh
  • 1,648
  • 2
  • 18
  • 36
  • What's the result of `command -v npm`? If it's on the `/mnt/...` path, then that could be the problem. Just not sure myself from the output I'm seeing in your question. – NotTheDr01ds Aug 10 '21 at 19:39
  • `command -v npm` returns `/usr/bin/npm` – ackh Aug 10 '21 at 19:46
  • See if [this](https://stackoverflow.com/a/62916945/11810933) works. Or anything else from that question. – NotTheDr01ds Aug 10 '21 at 20:27
  • Running `npm cache verify` seems to be unsupported by that version of npm. I'm getting ````npm ERR! Usage: npm cache add npm ERR! npm cache add npm ERR! npm cache add npm ERR! npm cache add npm ERR! npm cache add @ npm ERR! npm cache ls [] npm ERR! npm cache clean [[@]] ```` – ackh Aug 11 '21 at 06:59

2 Answers2

19

I found this article that detailed the steps that eventually enabled me to update npm. These are the steps that I followed:

  1. Step:
sudo npm cache clean -f
output:
npm WARN using --force I sure hope you know what you are doing.
  1. Step:
sudo npm install -g n
output:
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
└── n@7.3.1
  1. Step:
sudo n stable
output:
  installing : node-v14.17.4
       mkdir : /usr/local/n/versions/node/14.17.4
       fetch : https://nodejs.org/dist/v14.17.4/node-v14.17.4-linux-x64.tar.xz
   installed : v14.17.4 (with npm 6.14.14)

Note: the node command changed location and the old location may be remembered in your current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
  1. Step:
sudo n latest
output:
  installing : node-v16.6.1
       mkdir : /usr/local/n/versions/node/16.6.1
       fetch : https://nodejs.org/dist/v16.6.1/node-v16.6.1-linux-x64.tar.xz
   installed : v16.6.1 (with npm 7.20.3)
  1. Step: Close the shell and open a new one
  2. Step:
npm --version
output:
7.20.3
ackh
  • 1,648
  • 2
  • 18
  • 36
  • Did not work for me. I used `nvm` to upgrade node. This may have caused it to fail. Solution https://stackoverflow.com/a/68755757/481207 worked for me. – Matt May 02 '22 at 02:51
3

There's a workaround:

npm install -g yarn 
yarn global add npm 
~/.yarn/bin/npm install -g npm

Some thing to note:

  • my nodejs was installed using nvm under ~/.nvm
  • you need to close vscode if you have it running in wsl mode, and restart bash. some file might be hold by vscode-server process.
Leric
  • 193
  • 1
  • 7