开发者问题收集

npm 过时错误无法读取未定义的属性“长度”

2019-03-31
13984

我尝试从节点项目中的控制台运行“npm outdated”。但我收到此错误:

npm ERR! Cannot read property 'length' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2019-03-31T12_26_30_745Z-debug.log

这是日志中的错误:

199 verbose stack TypeError: Cannot read property 'length' of undefined
199 verbose stack     at dotindex (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\text-table\index.js:59:32)
199 verbose stack     at C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\text-table\index.js:11:21
199 verbose stack     at Array.forEach (<anonymous>)
199 verbose stack     at forEach (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\text-table\index.js:73:31)
199 verbose stack     at C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\text-table\index.js:10:9
199 verbose stack     at Array.reduce (<anonymous>)
199 verbose stack     at reduce (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\text-table\index.js:63:30)
199 verbose stack     at module.exports (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\text-table\index.js:9:20)
199 verbose stack     at C:\Users\amita\AppData\Roaming\npm\node_modules\npm\lib\outdated.js:130:16
199 verbose stack     at cb (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\slide\lib\async-map.js:47:24)
199 verbose stack     at outdated_ (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\lib\outdated.js:221:12)
199 verbose stack     at skip (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\lib\outdated.js:343:5)
199 verbose stack     at updateDeps (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\lib\outdated.js:446:7)
199 verbose stack     at tryCatcher (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
199 verbose stack     at Promise.successAdapter [as _fulfillmentHandler0] (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\nodeify.js:23:30)
199 verbose stack     at Promise._settlePromise (C:\Users\amita\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:566:21)
200 verbose cwd C:\Users\amita\Ionic\toratlechima
201 verbose Windows_NT 10.0.17134
202 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\amita\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "outdated"
203 verbose node v10.11.0
204 verbose npm  v6.9.0
205 error Cannot read property 'length' of undefined
206 verbose exit [ 1, true ]

当我尝试全局运行它时也会发生这种情况。 有人遇到过这种情况吗?

3个回答

似乎在下一个版本中得到修复,但尚未发布。

https://github.com/npm/cli/pull/173

您可以安装预发布版本来修复它。

npm -g i npm@next

更新

NPM 6.9.2 已经发布

npm install -g npm

Snæbjørn
2019-04-01

npm 中有一个错误,但您可以轻松修复它:

  1. 转到您的 npm 文件夹(即 /usr/local/lib/node_modules )并找到一个 outdated.js 文件(即 Mac /usr/local/lib/node_modules/npm/lib/outdated.js Windows C:\Users\YOUR_USER_NAME\AppData\Roaming\npm\node_modules\npm\lib\outdated.js
  2. 找到一个函数 makePretty 并将

    deppath
    

    更改为

    deppath || 'global'
    

就我而言,它是第 152 行

希望它有所帮助! 🙂

Pavel Kovalev
2019-04-04

您也可以尝试 npm upgrade -g 。对我来说很有效。

Antoine
2019-04-23