npm outdated error Cannot read property 'length' of undefined - node.js

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?

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

There is a bug in the npm, but you can easily fix it:
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)
Find a function makePretty and change
deppath
to
deppath || 'global'
in my case it was line #152
I hope it helps! 🙂

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

Here's how I successfully fixed the error after checking 'global' was in outdated.js file. Without any other requirements like brew etc, (type these commands in the terminal):
sudo npm cache clean -f (force) clear you npm cache
sudo npm install -g n install n (this might take a while)
sudo n stable upgrade to the current stable version
npm upgrade -g upgrade npm
Note that sudo might prompt your password.

Related

npm ERR! Unexpected end of JSON input while parsing near '...ain" : "src/index.js"' while running npm install -g #angular/cli

I get the the above error when I ran the command npm install -g #angular/cli
the complete logs are as below
verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...ain" : "src/index.js"'
78 verbose stack at JSON.parse (<anonymous>)
78 verbose stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
78 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50
78 verbose stack at processTicksAndRejections (internal/process/task_queues.js:97:5)
79 verbose cwd C:\Users\E079233\Coinnov\CoInnovUI
80 verbose Windows_NT 10.0.17763
81 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "#angular/cli"
82 verbose node v12.18.2
83 verbose npm v6.14.5
84 error Unexpected end of JSON input while parsing near '...ain" : "src/index.js"'
85 verbose exit [ 1, true ]
I tried npm cache clean --force and npm install #angular/cli#latest as suggested in another answer but it didn't work
Please suggest a possible way to fix this issue.
If you stumble upon this thread searching for answers and nothing suggested in other threads has helped you, then maybe the problem is in your private npm registry. As for me it was very slow responding and, as I think, connection closed eventually by timeout causing JSON with package metadata being invalid AND also storing such invalid JSON in npm cache.
The fix for me was to explicitly set registry for packages from our scope:
npm config set #myco:registry http://reg.example.com
This ensures that ONLY your company scope packages are downloaded from set registry, and others are from global registry. Also make sure you don't overwrite this setting by local .npmrc file in your repo root.
It seems you are seeing issues because of npm.
Please try out ::
npm cache clean --force
npm i -g npm
npm i -g #angular/cli#latest
npm i or npm install both are same. Please dont get confused

npm install reactjs app npm ERR! code E404

I am new to reactjs, and I am trying to create a reactjs app, and I follow the steps on react web, and it shows error. My node version is v8.11.1.npx version is 9.7.1.
btw I can create the app with npx create-react-app, but when fail with npm.
MacBook-teddy$ npm install -g create-react-app
create-react-app amber_Web
npm ERR! code E404
npm ERR! 404 Not Found: amber_Web#latest
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/teddy/.npm/_logs/2018-06-07T02_08_37_384Z-debug.log
And this is the log file:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli '-g',
1 verbose cli 'create-react-app',
1 verbose cli 'create-react-app',
1 verbose cli 'amber_Web' ]
2 info using npm#5.6.0
3 info using node#v8.11.1
4 verbose npm-session 452b1b32f613b960
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://registry.npmjs.org/create-react-app 32ms (from cache)
8 silly pacote tag manifest for create-react-app#latest fetched in 52ms
9 http fetch GET 404 https://registry.npmjs.org/amber_Web 1545ms
10 silly fetchPackageMetaData error for amber_Web#latest 404 Not Found: amber_Web#latest
11 verbose stack Error: 404 Not Found: amber_Web#latest
11 verbose stack at fetch.then.res (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/fetch.js:42:19)
11 verbose stack at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
11 verbose stack at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
11 verbose stack at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
11 verbose stack at Promise._settlePromise0 (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
11 verbose stack at Promise._settlePromises (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
11 verbose stack at Async._drainQueue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:133:16)
11 verbose stack at Async._drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:143:10)
11 verbose stack at Immediate.Async.drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
11 verbose stack at runCallback (timers.js:794:20)
11 verbose stack at tryOnImmediate (timers.js:752:5)
11 verbose stack at processImmediate [as _immediateCallback] (timers.js:729:5)
12 verbose cwd /Users/teddy/Desktop
13 verbose Darwin 17.5.0
14 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "create-react-app" "create-react-app" "amber_Web"
15 verbose node v8.11.1
16 verbose npm v5.6.0
17 error code E404
18 error 404 Not Found: amber_Web#latest
19 verbose exit [ 1, true ]
Thanks.
Looks like you tried to run create-react-app while installing it.
Run npm install -g create-react-app although this should already be installed.
Then run create-react-app amber-web
EDIT:
The reason this error out was because you put npm install -g create-react-app
create-react-app amber_Web all in one command telling npm to install the create-react-app package twice and the amber_Web package but that package doesn't exist hence the 404 error.
* name can no longer contain capital letters
The error is because npm follows the application naming conventions, according to which it is not allowed to use upper case letters in the application names also.
Kindly try using create-react-app amber_web
To learn more kindly visit : npmjs docs
try:
npm doctor
npm ping
"npm doctor runs a set of checks to ensure that your npm installation has what it needs to manage your JavaScript packages."
I think there could be problem in both cash and aslo react installation, so you should try:
npm cache clean --force
Then
npm install -g create-react-app
After that see your installation right or not by this
create-react-app --version
If it works then everything is ok now, but if not then you should try to uninstall node.js and try to search all it's caching folder delete them and install as frash node.js then insall react js.
try this
npm cache clean --force
and then
create-react-app your_app_name
Nothing helped me except
npm install -g webpack
npm -g list
├── create-react-app#5.0.1
└── webpack#5.73.0
Just set the registry as-
npm config set registry http://registry.npmjs.org
And then run
npm install -g create-react-app
create the project
npx create-react-app your_app_name

nodemon install error "No valid versions available for timed-out"

I am getting this error when trying to install nodemon in a brand new node project.
I've created a blank folder named my-project
then, inside it, I've executed to creeate a package.json file:
npm init -f
then when tryed to run
npm install --save-dev nodemon
And that was the result:
npm ERR! code ENOVERSIONS
npm ERR! No valid versions available for timed-out
I've just update my node version to the latest one and so npm tools.
node --version -> v8.9.4
npm --version -> 5.6.0
The funny part is that I've done this same steps in another computer 2 days ago with no problem.
325 verbose stack timed-out: No valid versions available for timed-out
325 verbose stack at pickManifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\npm-pick-manifest\index.js:20:11)
325 verbose stack at fetchPackument.then.packument (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\manifest.js:39:14)
325 verbose stack at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
325 verbose stack at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
325 verbose stack at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
325 verbose stack at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
325 verbose stack at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
325 verbose stack at Async._drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
325 verbose stack at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
325 verbose stack at Immediate.Async.drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
325 verbose stack at runCallback (timers.js:789:20)
325 verbose stack at tryOnImmediate (timers.js:751:5)
325 verbose stack at processImmediate [as _immediateCallback] (timers.js:722:5)
326 verbose cwd E:\githubprojects\my-project\server
327 verbose Windows_NT 10.0.16299
328 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save-dev" "nodemon#v1.14.7"
329 verbose node v8.9.4
330 verbose npm v5.6.0
331 error code ENOVERSIONS
332 error No valid versions available for timed-out
333 verbose exit [ 1, true ]
Official issue: https://github.com/npm/registry/issues/255
Official status: https://status.npmjs.org/incidents/41zfb8qpvrdj
Several packages including "require-from-string" are currently unavailable. We are aware of the issue and are working to restore the affected user and packages. Please do not attempt to republish packages, as this will hinder our progress in restoring them.
Update from NPM:
Resolved
We apologize for the temporary unavailability of some packages. We will be publishing a comprehensive post-mortem update in the next few days.
Posted Jan 06, 2018 - 23:14 UTC
timed-out is a npm package that is apparently missing, as of the last day, or hour, or minutes (I don't know the time span).
/Users/Stan ==> npm install timed-out -g
npm ERR! code ENOVERSIONS
npm ERR! No valid versions available for timed-out
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Stan/.npm/_logs/2018-01-06T20_26_40_854Z-debug.log
Now it is working.
/Users/Stan ==> npm install timed-out -g
+ timed-out#4.0.1
added 1 package in 1.306s
It's not you, it's an already known issue, due to dependency problems.
More details here https://github.com/remy/nodemon/issues/1210
Users are reporting that packages are being made available again. Try again and see if your issue is resolved.
https://github.com/npm/registry/issues/255

npm ERR! Invalid name: "#types/handlebars"

I was trying to install typedoc with npm, however seeing the following error:
npm ERR! Invalid name: "#types/handlebars"
I then tried to install #types/handlebars directly by:
npm install #types/handlebars
And the same error message shows up again. When I try to view package info by running:
npm info #types/handlebars
I can see the info correctly. What else should I check to tackle the problem?
I am using node v4.8.3 and npm v2.15.11 on OSX 10.10.5.
Here are the stack trace from npm-debug.log:
58 verbose etag https://registry.npmjs.org/#types%2fhandlebars from cache
59 verbose get saving #types/handlebars to /Users/ycchen/.npm/registry.npmjs.org/_40types_252fhandlebars/.cache.json
60 verbose correctMkdir /Users/ycchen/.npm correctMkdir not in flight; initializing
61 silly addNameTag next cb for #types/handlebars with tag latest
62 silly addNamed #types/handlebars#4.0.33
63 verbose addNamed "4.0.33" is a plain semver version for #types/handlebars
64 verbose stack Error: Invalid name: "#types/handlebars"
64 verbose stack at ensureValidName (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:297:15)
64 verbose stack at Object.module.exports.fixNameField (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:201:5)
64 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:29:38
64 verbose stack at Array.forEach (native)
64 verbose stack at normalize (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:28:15)
64 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:349:5)
64 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
64 verbose stack at ReadFileContext.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:295:20)
64 verbose stack at ReadFileContext.callback (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16)
64 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:303:13)
I suspect this has to do with where it is actually getting the types from. The info command works since it must be looking at official npm registry.
To try it out you can override the registry for specific scopes (#types in this case). For example:
npm config set #types:registry https://registry.npmjs.org/
This tells npm to always get anything for the #types scope directly from the official registry.
EDIT: I see from your edited question that npm does try to get it from the official registry so you might wish to get the latest npm since the version you are using is quite dated. You can do so by:
sudo npm cache clean
sudo npm install npm -g

npm install, node-gyp rebuild error

I'm just starting out working with node.js and when I try npm install I get an error stating Failed at the bcrypt#0.8.5 install script 'node-gyp rebuild'. After extensive googling I still have not found the problem.
Here's the error log:
Error Log
313 verbose stack Error: bcrypt#0.8.5 install: `node-gyp rebuild`
313 verbose stack Exit status 1
313 verbose stack at EventEmitter.<anonymous> (C:\Users\Apparaat1\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:239:16)
313 verbose stack at emitTwo (events.js:100:13)
313 verbose stack at EventEmitter.emit (events.js:185:7)
313 verbose stack at ChildProcess.<anonymous> (C:\Users\Apparaat1\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:24:14)
313 verbose stack at emitTwo (events.js:100:13)
313 verbose stack at ChildProcess.emit (events.js:185:7)
313 verbose stack at maybeClose (internal/child_process.js:827:16)
313 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
314 verbose pkgid bcrypt#0.8.5
315 verbose cwd D:\Werk\W12C\we12c\W12C
316 error Windows_NT 6.1.7601
317 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Apparaat1\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
318 error node v5.7.0
319 error npm v3.7.3
320 error code ELIFECYCLE
321 error bcrypt#0.8.5 install: `node-gyp rebuild`
321 error Exit status 1
322 error Failed at the bcrypt#0.8.5 install script 'node-gyp rebuild'.
322 error Make sure you have the latest version of node.js and npm installed.
322 error If you do, this is most likely a problem with the bcrypt package,
322 error not with npm itself.
322 error Tell the author that this fails on your system:
322 error node-gyp rebuild
322 error You can get information on how to open an issue for this project with:
322 error npm bugs bcrypt
322 error Or if that isn't available, you can get their info via:
322 error npm owner ls bcrypt
322 error There is likely additional logging output above.
323 verbose exit [ 1, true ]
Versions:
node -v
v5.7.0
npm -v
3.7.3
May be it's a little bit late but the solution in node-gyp
https://github.com/nodejs/node-gyp#installation
There are 2
different options.
Option 1: Install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global --production windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator).
Option 2: Install tools and configuration manually:
Visual C++ Build Environment:
Option 1: Install Visual C++ Build Tools using the Default Install option.
Option 2: Install Visual Studio 2015 (or modify an existing installation) and select Common Tools for Visual C++ during setup. This also works with the free Community and Express for Desktop editions.
Install Python 2.7 (v3.x.x is not supported), and run npm config set python python2.7 (or see below for further instructions on specifying the proper Python version and path.)
Launch cmd, npm config set msvs_version 2015
If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.
[Windows Vista / 7 only] requires .NET Framework 4.5.1

Resources