npm outdated -g Error ‘Cannot read property ‘length’ of undefined’

Tags: ,



I am trying to determine the version status of my npm installed global packages. After running the npm outdated -g --depth=0 in the terminal I receive this error:

npm ERR! Cannot read property 'length' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/dangranger/.npm/_logs/2019-03-14T21_58_37_962Z-debug.log

Contents of /Users/dangranger/.npm/_logs/2019-03-14T21_58_37_962Z-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/11.11.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'outdated',
1 verbose cli   '-g' ]
2 info using npm@6.9.0
3 info using node@v11.11.0
4 verbose npm-session 6182351d371bfeb5
5 http fetch GET 304 https://registry.npmjs.org/http-server 597ms (from cache)
6 silly pacote registry packument for http-server@^0.11.1 fetched in 616ms
7 http fetch GET 304 https://registry.npmjs.org/p5-manager 596ms (from cache)
8 silly pacote registry packument for p5-manager@^0.4.2 fetched in 618ms
9 http fetch GET 304 https://registry.npmjs.org/hpm-cli 603ms (from cache)
10 silly pacote registry packument for hpm-cli@^2.0.1 fetched in 621ms
11 http fetch GET 304 https://registry.npmjs.org/create-react-app 613ms (from cache)
12 http fetch GET 304 https://registry.npmjs.org/local-npm 607ms (from cache)
13 silly pacote registry packument for create-react-app@^2.1.1 fetched in 628ms
14 silly pacote registry packument for local-npm@^2.2.2 fetched in 627ms
15 http fetch GET 304 https://registry.npmjs.org/node-gyp 610ms (from cache)
16 silly pacote registry packument for node-gyp@^3.8.0 fetched in 631ms
17 http fetch GET 304 https://registry.npmjs.org/bower 623ms (from cache)
18 silly pacote registry packument for bower@^1.8.4 fetched in 638ms
19 http fetch GET 304 https://registry.npmjs.org/yarn 612ms (from cache)
20 silly pacote registry packument for yarn@^1.12.3 fetched in 635ms
21 http fetch GET 304 https://registry.npmjs.org/gatsby-cli 622ms (from cache)
22 silly pacote registry packument for gatsby-cli@^2.4.15 fetched in 641ms
23 http fetch GET 304 https://registry.npmjs.org/nodemon 620ms (from cache)
24 silly pacote registry packument for nodemon@^1.18.7 fetched in 644ms
25 http fetch GET 304 https://registry.npmjs.org/eslint 633ms (from cache)
26 silly pacote registry packument for eslint@^5.9.0 fetched in 653ms
27 http fetch GET 304 https://registry.npmjs.org/snyk 633ms (from cache)
28 silly pacote registry packument for snyk@^1.112.0 fetched in 662ms
29 http fetch GET 304 https://registry.npmjs.org/npm 647ms (from cache)
30 silly pacote registry packument for npm@^6.9.0 fetched in 682ms
31 verbose stack TypeError: Cannot read property 'length' of undefined
31 verbose stack     at dotindex (/usr/local/lib/node_modules/npm/node_modules/text-table/index.js:59:32)
31 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/text-table/index.js:11:21
31 verbose stack     at Array.forEach (<anonymous>)
31 verbose stack     at forEach (/usr/local/lib/node_modules/npm/node_modules/text-table/index.js:73:31)
31 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/text-table/index.js:10:9
31 verbose stack     at Array.reduce (<anonymous>)
31 verbose stack     at reduce (/usr/local/lib/node_modules/npm/node_modules/text-table/index.js:63:30)
31 verbose stack     at module.exports (/usr/local/lib/node_modules/npm/node_modules/text-table/index.js:9:20)
31 verbose stack     at /usr/local/lib/node_modules/npm/lib/outdated.js:130:16
31 verbose stack     at cb (/usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:47:24)
31 verbose stack     at outdated_ (/usr/local/lib/node_modules/npm/lib/outdated.js:221:12)
31 verbose stack     at skip (/usr/local/lib/node_modules/npm/lib/outdated.js:343:5)
31 verbose stack     at updateDeps (/usr/local/lib/node_modules/npm/lib/outdated.js:446:7)
31 verbose stack     at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
31 verbose stack     at Promise.successAdapter [as _fulfillmentHandler0] (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/nodeify.js:23:30)
31 verbose stack     at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:566:21)
32 verbose cwd /Users/dangranger
33 verbose Darwin 18.2.0
34 verbose argv "/usr/local/Cellar/node/11.11.0/bin/node" "/usr/local/bin/npm" "outdated" "-g"
35 verbose node v11.11.0
36 verbose npm  v6.9.0
37 error Cannot read property 'length' of undefined
38 verbose exit [ 1, true ]

Can anyone help resolve this issue for me?

Thanks

Answer

If you do not want to go through the bother of uninstalling and reinstalling Node, you can manually edit the “lib/outdated.js” file located in the “npm/node_modules/npm” path with the patch from the npm Github site at npm “outdated -g” patch

The fix is as simple as adding “|| ‘global'” to one line. Works fine and will stay in place until the next npm update.



Source: stackoverflow