npm -g doctor crashes with operation not permitted error on macOS 10.14 via Homebrew

What I Wanted to Do

npm -g doctor

What Happened Instead

Error: EPERM, Operation not permitted

Reproduction Steps

npm -g doctor

Details

Node is installed via Homebrew. Also tried removing /usr/local/lib/node_modules and ~/node_modules without luck.

$ cat ~/.npm/_logs/2019-10-18T14_28_38_725Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/Cellar/node/12.12.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   '-g',
1 verbose cli   'doctor'
1 verbose cli ]
2 info using npm@6.11.3
3 info using node@v12.12.0
4 verbose npm-session 46bcb3e856a6175a
5 info doctor Running checkup
6 info checkPing Pinging registry
7 notice PING https://registry.npmjs.org/
8 http fetch GET 200 https://registry.npmjs.org/-/ping?write=true 322ms
9 info getLatestNpmVersion Getting npm package information
10 http fetch GET 304 https://registry.npmjs.org/npm 44ms (from cache)
11 silly pacote tag manifest for npm@latest fetched in 71ms
12 info getLatestNodejsVersion Getting Node.js release information
13 info getGitPath Finding git in your PATH
14 warn checkFilePermissions Error: EPERM, Operation not permitted
14 warn checkFilePermissions     at /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js:49:16
14 warn checkFilePermissions     at ChildProcess.exithandler (child_process.js:286:7)
14 warn checkFilePermissions     at ChildProcess.emit (events.js:210:5)
14 warn checkFilePermissions     at maybeClose (internal/child_process.js:1021:16)
14 warn checkFilePermissions     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 warn checkFilePermissions  Error looking up user and group: Error: EPERM, Operation not permitted
14 warn checkFilePermissions     at /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js:49:16
14 warn checkFilePermissions     at ChildProcess.exithandler (child_process.js:286:7)
14 warn checkFilePermissions     at ChildProcess.emit (events.js:210:5)
14 warn checkFilePermissions     at maybeClose (internal/child_process.js:1021:16)
14 warn checkFilePermissions     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
14 warn checkFilePermissions   stack: 'Error: EPERM, Operation not permitted\n' +
14 warn checkFilePermissions     '    at /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js:49:16\n' +
14 warn checkFilePermissions     '    at ChildProcess.exithandler (child_process.js:286:7)\n' +
14 warn checkFilePermissions     '    at ChildProcess.emit (events.js:210:5)\n' +
14 warn checkFilePermissions     '    at maybeClose (internal/child_process.js:1021:16)\n' +
14 warn checkFilePermissions     '    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)',
14 warn checkFilePermissions   errno: 1
14 warn checkFilePermissions }
15 verbose stack Error: EPERM, Operation not permitted
15 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js:49:16
15 verbose stack     at ChildProcess.exithandler (child_process.js:286:7)
15 verbose stack     at ChildProcess.emit (events.js:210:5)
15 verbose stack     at maybeClose (internal/child_process.js:1021:16)
15 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
16 verbose cwd /Users/ianbytchek/Development/Bitwild/Gifox API
17 verbose Darwin 18.7.0
18 verbose argv "/usr/local/Cellar/node/12.12.0/bin/node" "/usr/local/bin/npm" "-g" "doctor"
19 verbose node v12.12.0
20 verbose npm  v6.11.3
21 error code [
21 error code   'EPERM',
21 error code   'EPERM',
21 error code   index: 0,
21 error code   input: 'EPERM, Operation not permitted',
21 error code   groups: undefined
21 error code ]
22 error errno 1
23 error EPERM, Operation not permitted
24 verbose exit [ 1, true ]

Platform Info

$ npm --versions
{
  npm: '6.12.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  llhttp: '1.1.4',
  modules: '72',
  napi: '5',
  nghttp2: '1.39.2',
  node: '12.12.0',
  openssl: '1.1.1d',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.32.0',
  v8: '7.7.299.13-node.12',
  zlib: '1.2.11'
}
$ node -p process.platform
darwin

I reproduced the failure, but I do not think -g is an option that is used with doctor and may not be a bug worth chasing. Just remove that to run the diagnostics:

npm doctor
1 Like