Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm outdated error Cannot read property 'length' of undefined

Tags:

node.js

npm

I try running 'npm outdated' from the console in my node project. But I get this error:

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

This is the error in the 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 ]

This also happens when I try to run it globally. Anyone encounter this?

like image 566
amitairos Avatar asked Mar 31 '19 12:03

amitairos


People also ask

Where can I find NPM err log for undefined undefined?

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 pm-cache\_logs\2019-03-31T12_26_30_745Z-debug.log

What does type error length of undefined mean?

A typeerror length of undefined can indicate that the actual type of an operand is different from the expected type. This error can be triggered with.length if the code is trying to access the property before it has been defined, so there needs to be a condition for when it returns undefined, and for when it does not return undefined.

Why does my JavaScript return undefined when I try to define?

This error can be triggered with .length if the code is trying to access the property before it has been defined, so there needs to be a condition for when it returns undefined, and for when it does not return undefined. In most cases, unless dealing with an external API , we can also just make sure to define it.

What does the length property return in JavaScript?

The length property returns a number for essentially any object in JavaScript. Typeerrors can be thrown when attempting to change a value that cannot be changed or when using a value in an inappropriate way.


3 Answers

Appears to be fixed in the next release, which isn't out yet.

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

You can install the pre-release to fix it.

npm -g i npm@next

Update

NPM 6.9.2 is out

npm install -g npm

like image 145
Snæbjørn Avatar answered Oct 04 '22 04:10

Snæbjørn


There is a bug in the npm, but you can easily fix it:

  1. Go to your npm folder (i.e. /usr/local/lib/node_modules) and find a outdated.js file (i.e. /usr/local/lib/node_modules/npm/lib/outdated.js for Mac or C:\Users\YOUR_USER_NAME\AppData\Roaming\npm\node_modules\npm\lib\outdated.js for Windows)
  2. Find a function makePretty and change

    deppath
    

    to

    deppath || 'global'
    

in my case it was line #152

I hope it helps! 🙂

like image 36
Pavel Kovalev Avatar answered Oct 04 '22 04:10

Pavel Kovalev


You can also try npm upgrade -g. Worked for me.

like image 40
antoine129 Avatar answered Oct 04 '22 05:10

antoine129