nvm: `nvm install-latest-npm` fails with "Cannot find module 'agentkeepalive'"

Operating system and version:

macOS 11.2 Big Sur

nvm debug output:

nvm --version: v0.37.2
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$SHLVL: 1
whoami: ***
${HOME}: ***
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:${NVM_DIR}/versions/node/v15.8.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/git/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 3.2.57(1)-release (arm64-apple-darwin20)'
uname -a: 'Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64'
checksum binary: 'shasum'
OS version: macOS 11.2 20D64
curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
wget: not found
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/local/bin/git, git version 2.30.0
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20200816
nvm current: v15.8.0
which node: ${NVM_DIR}/versions/node/v15.8.0/bin/node
which iojs: 
which npm: ${NVM_DIR}/versions/node/v15.8.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v15.8.0
npm root -g: ${NVM_DIR}/versions/node/v15.8.0/lib/node_modules

nvm ls output:

        v15.6.0
->      v15.8.0
default -> node (-> v15.8.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v15.8.0) (default)
stable -> 15.8 (-> v15.8.0) (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.23.3 (-> N/A)
lts/erbium -> v12.20.2 (-> N/A)
lts/fermium -> v14.15.5 (-> N/A)

How did you install nvm?

What steps did you perform?

What happened?

I installed the latest version of NodeJS and forgot to include the extra --latest-npm flag. After node v15.8 finished, I ran nvm install-latest-npm

nvm command output
Attempting to upgrade to the latest working version of npm...
* Installing latest `npm`; if this does not work on your node version, please report a bug!
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'agentkeepalive'
npm ERR! Require stack:
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/make-fetch-happen/agent.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/make-fetch-happen/index.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/pacote/lib/remote.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/pacote/lib/git.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/pacote/lib/fetcher.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/node_modules/pacote/lib/index.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/lib/utils/update-notifier.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/lib/cli.js
npm ERR! - …/.nvm/versions/node/v15.8.0/lib/node_modules/npm/bin/npm-cli.js

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 35 (13 by maintainers)

Most upvoted comments

Installing this

npm install -g agentkeepalive --save

then upgrading npm worked for me.

npm install -g npm fails with the same error.

nvm install-latest-npm worked for me guys…

It is something to do with 15.7. I just checked. Also after setting arch -x86_64 bash, I installed node 15.9 + npm 7.5.3 no problem. Curiously, I included --latest-npm and it installed 7.5.3 instead of the actual latest (7.5.4)

npm i -g npm@latest still fails with the Cannot find module 'agentkeepalive' error though (inside the arch x64 bash)

Reading the comments, it isn’t clear to me how this issue was resolved.

Here is what I am seeing (nvm@0.33.6, npm@7.6.3, node@14.16.0):

nvm install-latest-npm
Attempting to upgrade to the latest working version of npm...
nvm_install_latest_npm:68: command not found: 0
nvm_install_latest_npm:74: command not found: 0
* Installing latest `npm`; if this does not work on your node version, please report a bug!
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'agentkeepalive'
npm ERR! Require stack:
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/make-fetch-happen/agent.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/make-fetch-happen/index.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/pacote/lib/remote.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/pacote/lib/git.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/pacote/lib/fetcher.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/pacote/lib/index.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/lib/utils/update-notifier.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/lib/cli.js
npm ERR! - /Users/tschaub/.nvm/versions/node/v14.16.0/lib/node_modules/npm/bin/npm-cli.js

And npm install -g npm@latest fails with the same stack.

Was this closed because it is a problem with npm instead of nvm?

Update

I found https://github.com/nodejs/help/issues/3207 and saw the suggestion to run npm install -g npm (without latest or a version specified). This appears to have fixed the problem for me.

@ljharb I was having the same issue on m1 mac. this command nvm install 15.7 --latest-npm resolved the issues. Thanks

I know this is closed, but on a non-M1 Macbook Pro, it fails as well. Tried; npm install -g npm npm install -g npm@latest npm install -g npm@7.8.0

npm install -g npm npm ERR! code MODULE_NOT_FOUND npm ERR! Cannot find module 'agentkeepalive' npm ERR! Require stack: npm ERR! - /usr/local/lib/node_modules/npm/node_modules/make-fetch-happen/agent.js npm ERR! - /usr/local/lib/node_modules/npm/node_modules/make-fetch-happen/index.js npm ERR! - /usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js npm ERR! - /usr/local/lib/node_modules/npm/node_modules/pacote/lib/remote.js npm ERR! - /usr/local/lib/node_modules/npm/node_modules/pacote/lib/git.js npm ERR! - /usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetcher.js npm ERR! - /usr/local/lib/node_modules/npm/node_modules/pacote/lib/index.js npm ERR! - /usr/local/lib/node_modules/npm/lib/utils/update-notifier.js npm ERR! - /usr/local/lib/node_modules/npm/lib/cli.js npm ERR! - /usr/local/lib/node_modules/npm/bin/npm-cli.js

@JakobJingleheimer i just mean, “nvm install-latest-npm and then nvm install node” isn’t the same as “nvm install node --latest-npm”. “nvm install node --latest-npm” is the same as nvm install node && nvm install-latest-npm - note the reversed order.

Hm weird. I had the same error, but when I used nvm use (ran out of other options), the install worked. (Yes I used it before, but that was some days ago, so I was on the same version)

Run npm install -g agentkeepalive first. Should fix it.

npm install -g agentkeepalive

hm, 7.5.4 should def be installed; if npm install -g npm doesn’t do it, then I’d file a cli bug.

Can you try nvm install 15.7 --latest-npm now? I’m wondering if this is a bug in npm v7.5.3 - since node 15.7 came with npm v7.4.3, that would eliminate that possibility.