npm outdated -g 错误‘无法读取未定义的属性‘length’’
2019-03-14
2983
我正在尝试确定我的 npm 安装的全局包的版本状态。在终端中运行
npm outdated -g --depth=0
后,我收到此错误:
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
/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 [email protected]
3 info using [email protected]
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 ]
有人能帮我解决这个问题吗?
谢谢
2个回答
如果您不想费心卸载并重新安装 Node,可以使用 npm Github 站点上的补丁手动编辑位于“npm/node_modules/npm”路径中的“lib/outdated.js”文件,网址为 npm “outdated -g” patch
修复方法很简单,只需在一行中添加“|| 'global'”即可。效果很好,并且会一直保留到下一次 npm 更新。
Robert G. Schaffrath
2019-03-20
如果
||'global'
不起作用,请尝试这些,这对我有用:
打开
cmd
并转到根用户文件夹(例如
C:\Users\User
)并运行
npm install -g npm@latest
这会将您的 npm 更新为最新版本。再次尝试安装,现在应该可以正常工作了。
此外,您可以在
npm install -g npm@latest
之后使用
npm audit fix
Platinum
2020-12-10