58

When I'm trying to update npm to 7.20.3 (npm install -g npm@7.20.3), npm throws :

npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'agentkeepalive'
npm ERR! Require stack:
npm ERR! - /Users/ShaggyRogers/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/make-fetch-happen/agent.js
...
Thibault Walterspieler
  • 2,272
  • 2
  • 15
  • 25

3 Answers3

130

In order to quickly fix this error just install or re-install globally agentkeepalive :

npm install -g agentkeepalive --save

Then update npm :

npm install -g npm@7.20.3

UPDATE :

Since June 23 2021, the bug seems to be fixed in v7.17.0 (GitHub issue)

You can first upgrade to v7.17.0:

npm install -g npm@7.17.0

Then upgrade to the last version of npm :

npm install -g npm@7.21.0

or

npm install -g npm@latest
Thibault Walterspieler
  • 2,272
  • 2
  • 15
  • 25
1

This has been discussed on github

TL;DR;

It has been fixed in npm v7.17.0 and newer. I managed to upgrade from 7.10.0 to 7.21.0 and avoid this error entirely (and not dealing with agentkeepalive) by upgrading first to 7.17.0 and then to 7.21.0.

tromgy
  • 4,937
  • 3
  • 17
  • 18
  • I tried that but it didn't work. Aviator@AW:/mnt/c/Users/Adrian$ npm install -g npm@7.17.0 npm ERR! code MODULE_NOT_FOUND npm ERR! Cannot find module 'agentkeepalive' Installing agentkeepalive worked though. – Adrian Sep 25 '21 at 22:29
  • Maybe the "right" way is just to uninstall (https://docs.npmjs.com/cli/v7/using-npm/removal) and then install the latest. – tromgy Sep 26 '21 at 12:32
  • It appears to be back when upgrading from 7.13.0 to 8.1.3 – t j Nov 14 '21 at 02:30
  • 2
    It's not surprising, as 7.13.0 is older than 7.17.0 – tromgy Nov 14 '21 at 14:15
0

I do not know how, but this one worked for me:

$ npm --version
7.8.0
$ sudo npm uninstall -g npm

removed 252 packages, and audited 1 package in 586ms

found 0 vulnerabilities
$ sudo npm install -g npm

added 1 package, and audited 206 packages in 1s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
$ npm --version
8.17.0

Posting it as the accepted answer has not helped.

szz
  • 11
  • 1