我尝试从节点项目的控制台中运行“ npm过期”。但是我得到这个错误:
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 ]
当我尝试全局运行它时,也会发生这种情况。 有人遇到这个吗?
答案 0 :(得分:11)
答案 1 :(得分:9)
npm中有一个错误,但是您可以轻松修复它:
npm
文件夹(即/usr/local/lib/node_modules
)并找到一个outdated.js
文件(即对于{strong> Mac 或{{1} }用于 Windows )找到一个函数/usr/local/lib/node_modules/npm/lib/outdated.js
并更改
C:\Users\YOUR_USER_NAME\AppData\Roaming\npm\node_modules\npm\lib\outdated.js
到
makePretty
在我的情况下是#152行
希望对您有所帮助!
答案 2 :(得分:1)
您也可以尝试npm upgrade -g
。为我工作。
答案 3 :(得分:0)
这是在过时的.js文件中检查“ global”后,如何成功修复错误的方法。 没有其他要求,例如brew等,(在终端中键入以下命令):
sudo npm cache clean -f
(强制执行)清除npm缓存sudo npm install -g n
安装 n (这可能需要一段时间)sudo n stable
升级到当前的稳定版本npm upgrade -g
升级npm 请注意,sudo
可能会提示您输入密码。