首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >npm过时的-g错误‘无法读取属性’长度‘的未定义’

npm过时的-g错误‘无法读取属性’长度‘的未定义’
EN

Stack Overflow用户
提问于 2019-03-15 06:05:35
回答 2查看 2.7K关注 0票数 10

我正在尝试确定我的npm安装的全局包的版本状态。在终端中运行npm outdated -g --depth=0后,我收到以下错误:

代码语言:javascript
复制
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的内容

代码语言:javascript
复制
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 ]

有人能帮我解决这个问题吗?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-20 23:20:26

如果您不想经历卸载和重新安装Node的麻烦,您可以手动编辑位于" npm /node_modules/npm“路径中的"lib/outdated.js”文件,使用来自npm Github站点npm "outdated -g" patch的补丁

修复方法很简单,只需在一行中添加"|| 'global'“即可。运行良好,并将一直保持到下一次npm更新。

票数 19
EN

Stack Overflow用户

发布于 2020-12-11 02:14:15

如果||'global'不能工作,试试这些,这对我来说是有效的:

打开cmd并转到根用户文件夹,如C:\Users\User,然后运行npm install -g npm@latest

这会将您的npm更新到最新版本。再次尝试安装,现在应该可以正常工作。

此外,还可以在npm install -g npm@latest之后使用npm audit fix

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55172700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档