Cannot find module 'agentkeepalive' when updating NPM to 7.20.3 - node.js

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
...

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

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.

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.

Related

Can anyone update npm on the VS Code Terminal

I have recently updated npm on my cmd prompt in order to use yarn package manager. I want to be able to use yarn with Visual Studio Code, but I can not get the terminal in Visual Studio Code to update npm past v8.3.0
I've tried:
npm install
npm install -global npm#latest
npm install -g npm
npm i -g npm
npm update
npm update npm
npm update -g npm
npm update -global npm#latest (this command actually downgraded npm to 8.1.2)
Any help would be much appreciated
You can try to install n which is a package that lets you quick switch node version.
Install it with
sudo npm install -g n
Once installed you can select the preferred version
sudo n 8.3.0
REFERENCE: https://github.com/tj/n#installing-nodejs-versions

Why won't node update on Ubuntu, but has on Powershell?

Every time I start my ubuntu terminal I get this message saying the latest version of npm does not support my current version of node(15.13.0), but I went to Nodejs and installed v 16.13.0 yesterday and it installed fine in powershell but hasn't updated in ubuntu. I've tried running
sudo npm cache clean -f && sudo npm install -g n && sudo n stable
and got the following
npm WARN using --force Recommended protections disabled. changed 1 package, and audited 2 packages in 1s found 0 vulnerabilities npm notice npm notice New patch version of npm available! 8.1.0 -> 8.1.4 npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.1.4 npm notice Run npm install -g npm#8.1.4 to update! npm notice installed : v16.13.0 (with npm 8.1.0) awilbur#LAPTOP-ND9AON1L:/$ node -v v15.13.0
I've restarted my terminal and computer but nothing changed. Can anyone help?

Installing the Express Application Generator using npm

unable to install these package using npm: npm install eslint --save-dev , npm install -g express-generator
Both time give same error :**
npm ERR! Unexpected end of JSON input while parsing near '...0.2.13":{"name":"mini'
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2020-06-04T15_20_40_810Z-debug.log
but while installing another package npm install express it successfully installed
try to clean npm cache and then reinstall the packages
npm cache clean --force
npm install eslint --save-dev
npm install -g express-generator

Local grunt installation gives error

npm install -g grunt-cli //done successfully
npm install grunt --save --only=dev
gives following error
(node:11000) fs: re-evaluating native module sources is not supported. If
you are using the graceful
-fs module, please update it to a more recent version.
npm WARN prefer global coffee-script#1.10.0 should be installed with -g
project#1.0.0 C:\Users\Live\Desktop\node grunt\final
`-- (empty)
npm WARN project#1.0.0 No repository field.
npm ERR! code 1
Tried uninstalling grunt-cli, cleaning npm cache, then re-installing, but still the problem persists.
Ok short recap:
When in doubt remove your node_modules and install all packages again using npm install
If that didn't work, try updating your npm by executing npm update -g npm and redo step 1.
If that didn't solve your problem, try upgrading to another NodeJS version using nvm or n.

How can I update npm itself?

I am trying to update npm itself:
npm uninstall npm -g
Responds with:
unbuild npm#2.12.1
But when I go:
npm --version
I get 1.4.28? How to upgrade the npm itself?
By using this command you can update npm to the latest release by using npm itself :
npm i -g npm#latest
You can try this:
cd /usr/lib/node_modules
npm install npm#latest
Edit:
npm install -g npm worked for me.
See which version you have
npm -v
Install the newest npm update
npm install -g npm#latest
Upgrade to the most recent release
npm install -g npm#next
Upgrading on Windows
Microsoft wrote a small command-line tool to automate the steps below. You can go and download it here
https://docs.npmjs.com/try-the-latest-stable-version-of-npm

Resources