Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
felipecrs opened this issue Oct 14, 2020 · 45 comments
Closed
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@felipecrs
Copy link
Contributor

felipecrs commented Oct 14, 2020

Current Behavior:

$ npm install --global semver@7.3.1

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 npm@7.0.0
2 info using node@v12.19.0
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
@felipecrs felipecrs added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Oct 14, 2020
@pirouet
Copy link

pirouet commented Oct 17, 2020

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 npm@7.0.0
2 info using node@v14.13.0
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

@noseratio
Copy link

noseratio commented Oct 17, 2020

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

@somombo
Copy link

somombo commented Oct 19, 2020

seems to be fixed in v7.0.2

@matthewlynden
Copy link

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

@ttyrakow
Copy link

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

@Xanonymous-GitHub
Copy link

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

@wjhanna
Copy link

wjhanna commented Oct 22, 2020

npm@7.0.3 /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.

@WraithKenny
Copy link

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

@alaadahmed
Copy link

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.

@ljharb
Copy link
Collaborator

ljharb commented Oct 23, 2020

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.

@Niwotian60
Copy link

Niwotian60 commented Oct 23, 2020

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 npm\node_modules\npm\node_modules@npmcli\arborist\lib\arborist\build-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.

@lutzroeder
Copy link

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

@ErikAbele
Copy link

@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

  1. /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?

@alaadahmed
Copy link

@ErikAbele Yes I found out this later.

@ErikAbele
Copy link

@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/qubot@0.0.3-dev -> /home/erik/repos/codefaktor/qubot
├── node-red@1.2.2
├── npm@7.0.5
└── pm2@4.5.0

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/qubot@0.0.3-dev -> /Users/erik/Workzone/Projects/codefaktor.de/qubot
├── eslint@7.7.0
├── npm@7.0.3
├── truffle@5.1.42
└── yo@3.1.1

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! ;-)

@alaadahmed
Copy link

alaadahmed commented Oct 24, 2020

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 npm@7.0.5 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 npm@7.0.3 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

@ErikAbele
Copy link

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

@alaadahmed
Copy link

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

@ErikAbele
Copy link

I had npm@7.0.3 (which came with the fresh install of nodejs@15.0.1), then I added the prefix and updated to npm@7.0.5 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)...

@ErikAbele
Copy link

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

@alaadahmed
Copy link

I rollback to npm@6.14.8 but use node 15.0.1, and when they mark npm@7 as latest will upgrade it.

@GennaroDiFiandra
Copy link

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 'npm@7.0.5'. 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.

@alaadahmed
Copy link

You can read this and it will solve your issue: #1962 (comment)

@charles-dexter-ward
Copy link

charles-dexter-ward commented Oct 26, 2020

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

@jonathanmarvens
Copy link

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

@EatonZ
Copy link

EatonZ commented Nov 3, 2020

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

@ljharb
Copy link
Collaborator

ljharb commented Nov 3, 2020

Does this still happen on v7.0.7?

@dhtzs
Copy link

dhtzs commented Nov 4, 2020

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

@darcyclarke darcyclarke removed the Needs Triage needs review for next steps label Nov 4, 2020
@darcyclarke darcyclarke added this to the OSS - Sprint 19 milestone Nov 4, 2020
@msimonc
Copy link

msimonc commented Nov 4, 2020

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

@felipecrs
Copy link
Contributor Author

felipecrs commented Nov 4, 2020

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?

@msimonc
Copy link

msimonc commented Nov 5, 2020

@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

@ljharb
Copy link
Collaborator

ljharb commented Nov 5, 2020

Try npm v7.0.8?

@saschpe
Copy link

saschpe commented Nov 5, 2020

Try npm v7.0.8?

Issue persists :-(

@LeRoyJulian
Copy link

This issue is back again with today's homebrew upgrade

@felipecrs
Copy link
Contributor Author

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

@johncoryk
Copy link

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 :(

@ErikAbele
Copy link

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

@charles-dexter-ward
Copy link

charles-dexter-ward commented Nov 5, 2020

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.

@ruyadorno ruyadorno removed their assignment Nov 5, 2020
@djallits
Copy link

djallits commented Nov 7, 2020

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

@dhtzs
Copy link

dhtzs commented Nov 7, 2020

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.

@ErikAbele
Copy link

Thank you for looking into this, @isaacs!

isaacs added a commit to npm/arborist that referenced this issue Nov 10, 2020
This adjusts the portion of the global actualTree that gets loaded when
doing an update, and sets up the virtual global package manifest to
depend on '*' for all the packages being updated at the top global
level.

Fixes: npm/cli#1962
@ndmax
Copy link

ndmax commented Nov 10, 2020

Yay! Thank you @isaacs for cc0c6e1.

isaacs added a commit that referenced this issue Nov 10, 2020
* prevent self-assignment of parent/fsParent
* Support update options in global package space

Fix: #1962
@EatonZ
Copy link

EatonZ commented Nov 17, 2020

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

@AdemYuksel
Copy link

I updated to version 7.5.4 with npm install npm@7 -g and the problem is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests