Cli: [BUG] npm update --global fails: npm ERR! global requires an add or rm option

Created on 14 Oct 2020  ·  44Comments  ·  Source: npm/cli

Current Behavior:

$ npm install --global [email protected]

changed 1 package, and audited 1 package in 2s

found 0 vulnerabilities

$ npm update --global
npm ERR! global requires an add or rm option

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/felipesantos/.npm/_logs/2020-10-14T13_14_27_261Z-debug.log

$ npm update --global semver
npm ERR! global requires an add or rm option

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/felipesantos/.npm/_logs/2020-10-14T13_17_01_600Z-debug.log

$ cat /home/felipesantos/.npm/_logs/2020-10-14T13_14_27_261Z-debug.log
0 verbose cli [
0 verbose cli   '/home/felipesantos/.nvm/versions/node/v12.19.0/bin/node',
0 verbose cli   '/home/felipesantos/.nvm/versions/node/v12.19.0/bin/npm',
0 verbose cli   'update',
0 verbose cli   '--global'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/mnt/c/Users/felip/.npmrc Completed in 1ms
9 timing config:load:project Completed in 3ms
10 timing config:load:file:/home/felipesantos/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/home/felipesantos/.nvm/versions/node/v12.19.0/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 8ms
19 verbose npm-session 38aa94d0b0d83ff4
20 timing npm:load Completed in 14ms
21 timing arborist:ctor Completed in 0ms
22 timing command:update Completed in 2ms
23 verbose stack Error: global requires an add or rm option
23 verbose stack     at Arborist.buildIdealTree (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:185:29)
23 verbose stack     at Arborist.[loadTrees] (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:186:17)
23 verbose stack     at Arborist.reify (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:121:27)
23 verbose stack     at update (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/lib/update.js:34:13)
23 verbose stack     at cmd (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/lib/update.js:15:27)
23 verbose stack     at Object.[_runCmd] (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/lib/npm.js:112:7)
23 verbose stack     at fn (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/lib/npm.js:46:40)
23 verbose stack     at Object.<anonymous> (/home/felipesantos/.nvm/versions/node/v12.19.0/lib/node_modules/npm/lib/cli.js:56:7)
24 verbose cwd /mnt/c/Users/felip
25 verbose Linux 4.19.104-microsoft-standard
26 verbose argv "/home/felipesantos/.nvm/versions/node/v12.19.0/bin/node" "/home/felipesantos/.nvm/versions/node/v12.19.0/bin/npm" "update" "--global"
27 verbose node v12.19.0
28 verbose npm  v7.0.0
29 error global requires an add or rm option
30 verbose exit 1

Expected Behavior:

Before v7.0.0, running npm update --global would update all the packages installed globally which are outdated.

Steps To Reproduce:

Install an outdated global package, and try to update all the packages.

Environment:

  • OS: Ubuntu 20.04.1
  • Node: 12.19.0
  • npm: 7.0.0
Bug Release 7.x

Most helpful comment

Doesn't look like v7.0.9 is going to fix the issue either.

The bug has been acknowledged and a fix is scheduled for an upcoming release.

All 44 comments

Can confirm this happens for me too ...

➜  event-centre npm -v 
7.0.0
➜  event-centre npm -g update
npm ERR! global requires an add or rm option

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/michael/.npm/_logs/2020-10-17T21_49_17_159Z-debug.log
➜  event-centre cat /Users/michael/.npm/_logs/2020-10-17T21_49_17_159Z-debug.log 
0 verbose cli [
0 verbose cli   '/Users/michael/.nvm/versions/node/v14.13.0/bin/node',
0 verbose cli   '/Users/michael/.nvm/versions/node/v14.13.0/bin/npm',
0 verbose cli   '-g',
0 verbose cli   'update'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/npmrc Completed in 0ms
5 timing config:load:builtin Completed in 0ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Volumes/Developer/event-centre/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/michael/.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/Users/michael/.nvm/versions/node/v14.13.0/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 7ms
19 verbose npm-session 7a6ea29e573a5509
20 timing npm:load Completed in 12ms
21 timing arborist:ctor Completed in 0ms
22 timing command:update Completed in 3ms
23 verbose stack Error: global requires an add or rm option
23 verbose stack     at Arborist.buildIdealTree (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:185:29)
23 verbose stack     at Arborist.[loadTrees] (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:186:17)
23 verbose stack     at Arborist.reify (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:121:27)
23 verbose stack     at update (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/lib/update.js:34:13)
23 verbose stack     at cmd (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/lib/update.js:15:27)
23 verbose stack     at Object.[_runCmd] (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/lib/npm.js:112:7)
23 verbose stack     at fn (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/lib/npm.js:46:40)
23 verbose stack     at Object.<anonymous> (/Users/michael/.nvm/versions/node/v14.13.0/lib/node_modules/npm/lib/cli.js:56:7)
24 verbose cwd /Volumes/Developer/event-centre
25 verbose Darwin 19.6.0
26 verbose argv "/Users/michael/.nvm/versions/node/v14.13.0/bin/node" "/Users/michael/.nvm/versions/node/v14.13.0/bin/npm" "-g" "update"
27 verbose node v14.13.0
28 verbose npm  v7.0.0
29 error global requires an add or rm option
30 verbose exit 1

npm update --global fails: npm ERR! global requires an add or rm option

Same error if I just want to update global packages:

npm -g update

Or

npm -g upgrade

Seeing it with v7.0.1 on Windows and Debian 10.

These worked for 6.x

seems to be fixed in v7.0.2

I'm still seeing the same issue with 7.0.2

$ npm -v
7.0.2

$ npm -g update
npm ERR! global requires an add or rm option

I can confirm the same behavior in npm 7.0.3 on Windows 10 x64. Just upgraded from npm@6 and got this surprise.

npm v 7.0.2 on macOS nodejs v15 has same problem.

npm ERR! global requires an add or rm option
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user/.npm/_logs/2020-10-21T09_28_30_807Z-debug.log

[email protected] /Users/username/.nvm/versions/node/v15.0.1/lib/node_modules/npm

❯ npm update -g
npm ERR! global requires an add or rm option

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2020-10-22T20_49_47_598Z-debug.log

Same issue for me. MacOS, npm v7.0.3. Using nvm.

Same. On MacOS, with Brew.

I brew rm node and brew install node to fix the issue of npm ls -g not showing any packages.

After that, I npm i npm@^6 -g then ran npm update -g (actually, I also did npm update eslinst@lastest -g first)

I then ran npm i npm@latest -g and now npm update -g doesn't report an error. (There's no updates available anymore, but it seems fixed for me, for now.)

I did the same as @WraithKenny, but with the difference that I npm i npm -g without specifying @^6 and it will install by default __ver 6.14.8__, but then when you npm list -g, it shows nothing. I then reinstalled npm but ver 7 >> npm i npm@7 -g and now there are no errors and when I npm list -g it shows all globally installed packages, and no errors anymore.

Because npm 7 isn’t “latest”, you don’t want to use npm install -g npm once you’re on npm 7, as that will downgrade it to 6. Use @7 to ensure you stay on v7.

I encountered this problem today on Win 10 after updating node to version 15.0.1 and concomitantly npm to version 7.0.5. A quick look at the files in the debug log stack trace points to the following lines (184-5) in file npmnode_modulesnpmnode_modules@npmcli\arboristlib\arboristbuild-ideal-tree.js:

    if (!options.add && !options.rm && this[_global])
      return Promise.reject(new Error('global requires an add or rm option'))

This is my first delve into the underlying code and it isn't clear to me from the context around these lines what their intended purpose is but they clearly put a hard stop to any global update actions other than add or rm.

brew install nodejs
npm update --global --quiet
npm ERR! global requires an add or rm option

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxxxxxxx/.npm/_logs/2020-10-24T04_20_28_320Z-debug.log

@WraithKenny @alaadahmed You both probably have two global node_modules directories now, right?

1) /usr/local/lib/node_modules (with npm 6.14.8 and all your previous global modules)

and

2) /usr/local/Cellar/node/15.0.1/lib/node_modules (with npm 7.0.5 and zero global modules (yet))

And calling npm will use 6.14.8 but display the modules in /usr/local/Cellar/node/15.0.1/lib/node_modules, right?

@ErikAbele Yes I found out this later.

@ErikAbele Yes I found out this later.

Aye, seeing the same here on OSX :-( I got it all sorted on my Ubuntu 20.04 box but as soon as I try to update npm to 7.0.5 on OSX it switches my global node_modules directory to /usr/local/Cellar/node/15.0.1/...:

Ubuntu 20.04:

erik@RaspberryPi:~$ which npm 
/usr/bin/npm
erik@RaspberryPi:~$ npm --version
7.0.5
erik@RaspberryPi:~$ npm list -g
/usr/lib
├── @codefaktor/[email protected] -> /home/erik/repos/codefaktor/qubot
├── [email protected]
├── [email protected]
└── [email protected]

MacOS X:

[erik@Odin ~]% which npm                                                                                                                                                                                                           14:26:48
/usr/local/bin/npm
[erik@Odin ~]% npm --version                                                                                                                                                                                                       14:32:30
7.0.3
[erik@Odin ~]% npm list -g                                                                                                                                                                                                         14:32:36
/usr/local/lib
├── @codefaktor/[email protected] -> /Users/erik/Workzone/Projects/codefaktor.de/qubot
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

And as soon as I do a npm install npm@7 -g on the latter I get it all messed up again :-/ So if anybody knows how to fix that over there I'd appreciate a ping, TIA! ;-)

OK I did the following and it solved the problem of newly created path for global packages:

1- npm config set prefix '/usr/local' >> this will set the path for global installed packages and it will search for folder lib inside this path and then will install any package in node_modules folder inside lib .. so for macOS it will find all your installed packages inside /usr/local/lib/node_modules >> but this will work with [email protected] not 7.0.3 so you need to check which version of npm you have.
After I upgraded node to 15.0.1 it installed [email protected] so I configured prefix path as shown in step __1__ then and only then I updated npm to 7.0.5 with npm i npm -g
Now when I npm list -g it shows all my packages installed before. Also npm update -g works fine.

I think for ubuntu you need to make npm config set prefix '/usr' so it will search for lib folder at that path, and will install any package inside node_modules under lib so complete path will be /usr/lib/node_modules

__update__: it still doesn't work with npm@7 .. but works with npm@6 and node 15.0.1 with the path to packages fixed to /usr/local/lib/node_modules
I still suffer with npm@7 under node 15.0.1

Excellent, this finally did the trick – thank you!

(Weird, npm config get prefix already had that path but setting it another time really prevented the creation of the second directory structure.)

@ErikAbele OK now which version of npm you have?! And if npm@7 can you make npm update -g?!

I had [email protected] (which came with the fresh install of [email protected]), then I added the prefix and updated to [email protected] via npm install npm@7 -g and I now have 7.0.5 in /usr/local/lib/...

npm update -g still does not work but npm outdated -g works for the correct path and I can simply do e.g. npm install eslint@latest -g to update specific packages with the latest npm at the correct path. That's all I need for now (and until npm has been fixed upstream)...

I guess as long as 7.0.5 is not marked as being latest (and instead 6.14.8 is) we will have to live with that... :-/

I rollback to [email protected] but use node 15.0.1, and when they mark npm@7 as __latest__ will upgrade it.

Good morning at all. I have the same problem.

If I do "npm upadate -g" it give me "global requires an add or rm option" and if I do "npm list -g" it give me '[email protected]'. If I downgrade to npm 6, the problem persists.

My real problem is that I had many packages installed globally and I don't remember all. There is a way to recover them?

I'm on macOS Mojave.

You can read this and it will solve your issue: https://github.com/npm/cli/issues/1962#issuecomment-715911549

Nodejs 15.0.1
npm 7.0.3

Using "npm set config ", pointing to my user profile folder. It now points to the correct modules folder, but now, executing an outdated request (npm outdated -g) it lists way way more outdated packages .

image

and the list continues for a lot more packages ...

I’m running into all of the issues on this thread 😞 . . . downgrading back to v6.14.8 until these issues are resolved

npm 7.0.6 is out and the same problem still persists. ;o(

Is an official fix being worked on yet? Right now I can't update my global packages without re-installing them.

Does this still happen on v7.0.7?

NPM v7.0.8 is out and the bug still exists. Please, do something about it.

Potential Work Around, Mac:
Use n to install then switch to a new node/npm version.
https://github.com/tj/n
Then switch back and
sudo npm -g update should work

Potential Work Around, Mac:
Use n to install then switch to a new node/npm version.
https://github.com/tj/n
Then switch back and
sudo npm -g update should work

What's the output of sudo npm --version?

@felipecrs it's going to depend on the version installed using n.
Mine: npm 6.14.8 when node is v12.13.1

Potential Work Around, Mac:
Use n to install then switch to a new node/npm version.
https://github.com/tj/n
Then switch back and
sudo npm -g update should work

What's the output of sudo npm --version?

@felipecrs it's going to depend on the version installed using n.
Mine: npm 6.14.8 when node is v12.13.1

Try npm v7.0.8?

Try npm v7.0.8?

Issue persists :-(

This issue is back again with today's homebrew upgrade

Just to sort this out, it's an issue with npm v7 no matter what node version (such as 15).

Can confirm this issue persists... Have we heard of a fix being worked on? Just got a new work computer last week and have not had any luck :(

@felipecrs et al: yes, you're right, it is an issue with just npm@7 – I just tried with latest 7.0.8 and the issue persists.

I completely removed Node and npm module folder in my %USERAPPDATA%.
Reinstalled node (15.0.1).
Upgraded npm to 7.07.

1) npm outdated -g
gives a list of a lot of modules which are outdated

2) npm list -g --depth=0
Now it lists the modules (before it only shown npm)

3) npm update npm -g
(to update npm to 7.0.8)
npm ERR! global requires an add or rm option

Conclusion:
reinstalling everything fixes something but npm error persists. I think that this is not a viable way, also.

Doesn't look like v7.0.9 is going to fix the issue either.

Doesn't look like v7.0.9 is going to fix the issue either.

The bug has been acknowledged and a fix is scheduled for an upcoming release.

Thank you for looking into this, @isaacs!

Yay! Thank you @isaacs for cc0c6e1.

Thanks a lot for fixing this. When do you expect the next update to release with this fix?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaydenseric picture jaydenseric  ·  3Comments

darcyclarke picture darcyclarke  ·  3Comments

chrisspen picture chrisspen  ·  3Comments

CliffS picture CliffS  ·  3Comments

1000i100 picture 1000i100  ·  3Comments