npm hangs while trying to install gulp - node.js

UPDATED:
When I try to install any package with 'npm install', or any variant:
npm install gulp -g -verbose
npm install gulp -verbose
npm install gulp
npm install
npm install connect
I get the following output but it just hangs on the last line, never finishing the install:
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'install',
npm verb cli 'gulp',
npm verb cli '-g',
npm verb cli '-verbose' ]
npm info using npm#2.5.1
npm info using node#v0.12.0
npm verb node symlink C:\Program Files\nodejs\\node.exe
npm verb cache add spec gulp
npm verb addNamed gulp#*
npm verb addNameRange registry:https://registry.npmjs.org/gulp not in flight; fetching
npm verb request uri https://registry.npmjs.org/gulp
npm verb request no auth needed
npm info attempt registry request try #1 at 4:09:05 PM
npm verb request id 77dfc5813704dba8
npm verb etag "EOZJDNUCAN683DXC55T2W1JVT"
npm http request GET https://registry.npmjs.org/gulp
npm http 304 https://registry.npmjs.org/gulp
npm verb etag https://registry.npmjs.org/gulp from cache
npm verb get saving gulp to C:\Users\iwiegand.TMI\AppData\Roaming\npm-cache\registry.npmjs.org\gulp\
.cache.json
npm verb addNamed gulp#3.8.11
npm verb addRemoteTarball https://registry.npmjs.org/gulp/-/gulp-3.8.11.tgz not in flight; adding
npm verb addRemoteTarball [ 'https://registry.npmjs.org/gulp/-/gulp-3.8.11.tgz',
npm verb addRemoteTarball 'd557e0a7283eb4136491969b0497767972f1d28a' ]
^CTerminate batch job (Y/N)?
It's definitely not https, since changing it to http yields the same result. It does this from any folder on my machine, no matter what package, or even just 'npm install'. I've restarted, resintalled node.js, etc. I'm on a Windows 8.1 machine and wishing I had a Mac.
The crazy thing is it HAS worked. I got Composer, Laravel and a bunch of other stuff installed just fine, then one day, it just started doing this. I have no idea what could be interfering. Checking the TaskManager, npm IS running with like 18% CPU usage the whole time it's "trying" to install.
Apparently I'm the only one on Earth with this problem. I've searched and searched on Google and nothing. I'm resorting to Facebook and Google groups. So far no suggestions from SO users have helped, although I very much appreciate the attempts.

I recently came across this problem and managed to fix it, on my own machine at least, by correcting my TEMP environment variable that had been mucked with by some other installer or npm package. I found an issue on github that was describing the exact same problem and I posted my discovery and resolution there.
Basically, someone had appended ;C:\Python27 to the end of my TEMP which was screwing up the unpacking of the npm module. So, maybe it's a long shot, but check it out and see if it works for you!

Related

getting "Error: EINVAL: invalid argument, read" for "npm install --save-dev eslint --verbose"

Any ideas/assistance here re how to get "npm install --save-dev eslint --verbose" working. I keep getting:
Error: EINVAL: invalid argument, read
I've setup up a new react-native project:
react-native init gcLists
E:\gcLists>npm -v
5.5.1
E:\gcLists>yarn -v
1.2.1
E:\gcLists>react-native -v
react-native-cli: 2.0.1
react-native: 0.49.5
npm install --save-dev eslint --verbose
Last part of the log:
npm http fetch GET 304 https://registry.npmjs.org/slice-ansi 104ms (from cache)
npm verb correctMkdir D:\Users\greg\AppData\Roaming\npm-cache\_locks correctMkdir not in flight; initializing
npm verb lock using D:\Users\greg\AppData\Roaming\npm-cache\_locks\staging-255cd84f0d76b150.lock for E:\gcLists\node_modules\.staging
npm info lifecycle semver#5.4.1~preuninstall: semver#5.4.1
npm info lifecycle semver#5.4.1~uninstall: semver#5.4.1
npm verb unbuild rmStuff semver#5.4.1 from E:\gcLists\node_modules
npm verb unlock done using D:\Users\greg\AppData\Roaming\npm-cache\_locks\staging-255cd84f0d76b150.lock for E:\gcLists\node_modules\.staging
npm verb stack Error: EINVAL: invalid argument, read
npm verb stack at D:\Users\greg\AppData\Roaming\npm\node_modules\npm\lib\utils\gently-rm.js:275:7
npm verb stack at D:\Users\greg\AppData\Roaming\npm\node_modules\npm\node_modules\iferr\index.js:13:50
npm verb stack at D:\Users\greg\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
npm verb stack at FSReqWrap.oncomplete (fs.js:154:5)
npm verb cwd E:\gcLists
npm verb Windows_NT 6.1.7601
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "D:\\Users\\greg\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save-dev" "eslint" "--verbose"
npm verb node v8.7.0
npm verb npm v5.5.1
npm ERR! code EINVAL
npm ERR! EINVAL: invalid argument, read
npm verb exit [ 1, true ]
npm ERR! A complete log of this run can be found in:
npm ERR! D:\Users\greg\AppData\Roaming\npm-cache\_logs\2017-11-03T02_38_08_842Z-debug.log
Notes:
On Windows 7
UPDATE:
* Results of npm install --save-dev eslint --verbose may be found here.
Since you are using drive letter E:, you might be on a portable drive. I had the same problem using an USB-Stick formatted on FAT32. I solved it reformatting to NTFS.
What helped me was to also delete my package-lock.json file.
rm -rf node_modules package-lock.json
npm i
Sometimes some packages have issues with npm. This could be base on combination of OS/package version/node version/npm version compatibility issue.
In such cases best thing is to do is try and use some other package manager. Try this with yarn
yarn add eslint
Same problem happened to me and what i did was deleting the whole node_modules folder and run npm install again. It fixed the error.
The reason was in the initial npm install it was closed in the middle by me which crashed some files.
Try cleaning the npm cache:
npm cache clean
Then try again.
I was getting the error when I did npm update so i deleted some npm outdated node_modules and ran npm update again and it worked.
yarn upgrade also fixed the thing.

How does npm handle lock files

So I'm running npm install xyz inside a script that is called by the postinstall npm hook of another npm module. (Let's not get into why please but it has to do with optional dependencies that are not supported by npm)
npm install moduleA
-> installing moduleA
-> running postinstall hook (my script)
-> my script runs npm install xyz
When I run the script itself the npm install runs reasonably fast but when I install the module within the postinstall hook the script waits on a lock file for at least 1 min. (or so I assume)
When I enable verbose loglevel in npm I get an output like below:
[a lot more lines above]
npm verb addNamed "latest" is being treated as a dist-tag for invert-kv
npm info addNameTag [ 'invert-kv', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/invert-kv already in flight; waiting
npm verb addNamed "1.0.0" is a plain semver version for invert-kv
npm verb afterAdd /Users/path/.npm/invert-kv/1.0.0/package/package.json not in flight; writing
npm verb correctMkdir /Users/path/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/path/.npm/invert-kv/1.0.0/package/package.json written
npm verb cache add spec camelcase#^3.0.0
npm verb addNamed ">=3.0.0 <4.0.0" is a valid semver range for camelcase
npm verb addNameRange registry:https://registry.npmjs.org/camelcase not in flight; fetching
npm verb get https://registry.npmjs.org/camelcase not expired, no request
npm verb addNamed "3.0.0" is a plain semver version for camelcase
npm verb afterAdd /Users/path/.npm/camelcase/3.0.0/package/package.json not in flight; writing
npm verb correctMkdir /Users/path/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/path/.npm/camelcase/3.0.0/package/package.json written
npm verb correctMkdir /Users/path/.npm/_locks correctMkdir not in flight; initializing
waits here for at least one minute
npm verb lock using /Users/path/.npm/_locks/staging-d21af557b41d4821.lock for /Users/path/Desktop/t/node_modules/.staging
npm verb unbuild node_modules/.staging/abbrev-ac014442
npm verb unbuild node_modules/.staging/ansi-regex-12e09986
npm verb unbuild node_modules/.staging/ansi-styles-1359ba2f
npm verb unbuild node_modules/.staging/aproba-d9971840
npm verb unbuild node_modules/.staging/array-find-index-c1ddfc4c
[a lot more lines below]
Now looking at the code of correctMkdir it seems that to just load all all files in /Users/path/.npm/_locks into memory and try to repair permission? Not sure.
correctMkdir is called by lock. This seems to hash the file and some encryption? Also not sure.
After reverse engineering some npm code I made progress by changing the config for cache-lock-stale, cache-lock-wait to 10ms. Unfortunately it still hangs for way too long before installing everything correctly. I suspect the changed config is not taken into account when changing right before and npm being inflight? Maybe? Maybe it's something entirely different? :)
Anyone who can hint me the right direction? Is there something I can do to speed things up?
After a night of sleep the install now seems to be much faster. I'm guessing some caching was still hang in my _locks folder.
So the answer was:
Set cache-lock-stale and cache-lock-wait to 10ms each temporarily and npm won't wait for your lock file to expire. As I understand it npm is trying to wait for all lock files in the _lock folder to be finished and because we are running npm install inside npm install the lock file from the parent process is still in use obviously. This is all more of a guess but I hope it helps someone in the future.

NPM install hangs on loadRequestedDeps

When I download any package using NPM, it hangs on the last command "loadRequestedDeps." I've added my whole -verbose output to the end of this question for reference. It will just sit there until I cancel the command, and nothing will be installed and my package.json will not be updated.
What could the issue be? I've looked around but haven't found out how to fix my particular problem.
Here's some info:
OS is Windows 10
Node version is 6.9.1
NPM version is 3.10.8
My CPU maxes out at 100% whenever I run NPM install. Could that be the issue itself? I used to be able to use NPM install on this computer, however.
Thanks for anyone who can help. The verbose output is below.
npm info it worked if it ends with ok
npm info using npm#3.10.8
npm info using node#v6.9.1
npm info ok
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'install',
npm verb cli 'moment',
npm verb cli '--save',
npm verb cli '-verbose' ]
npm info using npm#3.10.8
npm info using node#v6.9.1
npm verb request uri https://registry.npmjs.org/moment
npm verb request no auth needed
npm info attempt registry request try #1 at 11:19:11 AM
npm verb request id 6aa9ece5a04fcd33
npm verb etag W/"583b0871-194b0"
npm verb lastModified Sun, 27 Nov 2016 16:23:13 GMT
npm http request GET https://registry.npmjs.org/moment
npm http 304 https://registry.npmjs.org/moment
npm verb headers { date: 'Tue, 29 Nov 2016 19:19:02 GMT',
npm verb headers via: '1.1 varnish',
npm verb headers 'cache-control': 'max-age=300',
npm verb headers etag: 'W/"583b0871-194b0"',
npm verb headers age: '11',
npm verb headers connection: 'keep-alive',
npm verb headers 'x-served-by': 'cache-sjc3136-SJC',
npm verb headers 'x-cache': 'HIT',
npm verb headers 'x-cache-hits': '1',
npm verb headers 'x-timer': 'S1480447142.653125,VS0,VE0',
npm verb headers vary: 'Accept-Encoding' }
npm verb etag https://registry.npmjs.org/moment from cache
npm verb get saving moment to C:\Users\Zach\AppData\Roaming\npm-cache\registry.npmjs.org\moment\.cache.json
npm verb correctMkdir C:\Users\Zach\AppData\Roaming\npm-cache correctMkdir not in flight; initializing
npm verb cache add spec moment
npm verb addNamed "latest" is being treated as a dist-tag for moment
npm info addNameTag [ 'moment', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/moment not in flight; fetching
npm verb get https://registry.npmjs.org/moment not expired, no request
npm verb addNamed "2.17.0" is a plain semver version for moment
npm verb addRemoteTarball https://registry.npmjs.org/moment/-/moment-2.17.0.tgz not in flight; adding
npm verb addRemoteTarball [ 'https://registry.npmjs.org/moment/-/moment-2.17.0.tgz',
npm verb addRemoteTarball 'a4c292e02aac5ddefb29a6eed24f51938dd3b74f' ]
[ ..............] \ loadRequestedDeps: verb addRemoteTarball [ 'https://registry.npmjs.org/moment/-/moment-2.17.0.tgz',
I had this exact same issue, and it drove me crazy for about a day before I found these solutions.
After creating a new "tmp" folder in my C drive, and then changing the TEMP variable in my SYSTEM Environment variables to C:\tmp.
My "npm install" was still not working. (This action was based on Zach Nagatani's answer.)
I also had two TEMP variables defined in my USER Environment variables, and I had to delete one of the variables for my "npm install" to start working.
The above action was based on this post: https://github.com/npm/npm/issues/7590
I was so glad when I found it. Many thanks to you all.
Create new folder tmp in C: drive and go to the command prompt and type:
npm config set tmp C:/tmp
this is very general error ..
you have to debug with
npm install -verbose
it maybe
1) locked package.json
2) you are in private network and can't access outside world for some reason
3) cache is not good ( you may try with npm clear cache ) or ( cache verify ) or even changing its path (npm config set tmp )
npm cache verify did the trick for me!
EDIT
npm was stuck on loadAllDepsIntoIdealTree.
I couldn't figure out the issue, so it got me here. I saw #franckstifler's answer about npm cache clear and tried that, but the command was deprecated.
The shell itself instead suggested using npm cache verify. I did that and it worked! The garbage data in cache got swiped away and I rerun npm i --save-dev on my working folder and it worked.
Sometimes when you have tried several times to install a package, you need to clear your cache: npm cache clear. But yarn is a really better option compared to npm, it is fast and reliable. Install it with npm -i -g yarn and to download dependencies yarn add package_name from a package.json you use yarn install.
So, after trying to clear the npm cache, update my npm and node version, reinstalling npm and node, etc... I found that changing my Environment Variable TEMP to = C:\tmp worked. I'm not sure why. Any info would be nice.
I found the answer from this thread: npm install hangs on windows with multiple temp directories set
NOTE: I could use the method he uses (using the set command on my directory, but I had to do this with every new project. Changing the variable via System, Advanced System Settings, Environment Variables changed it globablly, so now I'm all good to go.
i tried googling nothing worked for me finally i found the fix by setting the environment varible
try use https://github.com/npm/npm/issues/10462
Finally Resolved The Problem(Wondering)
Change Both System And User TEMP Variable point to C:\temp and make a directory as C:\temp.
1.TEMP=C:\temp;
2.Make A Directory temp at C:\

npm install does not work when running npm install cordova

I am using Ionic framework to build hybrid apps. According to the official website, i need to get the version 4.2.4 of Node.js, which includes npm package manager. One of the dependencies needed by Ionic is cordova so that i run the following command to get it
C:\Users\ferrero>npm install -g cordova
After then, the console logs
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'prefix',
npm verb cli '-g' ]
npm info using npm#2.14.12
npm info using node#v4.2.4
npm verb exit [ 0, true ]
npm info ok
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm- cli.js',
npm verb cli 'install',
npm verb cli 'cordova' ]
npm info using npm#2.14.12
npm info using node#v4.2.4
npm verb config Skipping project config: C:\Users\ferrero/.npmrc.
(matches userconfig)
npm verb install initial load of C:\Users\ferrero\package.json
npm verb readDependencies loading dependencies from C:\Users\ferrero\package.json
npm verb cache add spec cordova
npm verb addNamed "latest" is being treated as a dist-tag for cordova
npm info addNameTag [ 'cordova', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/cordova not in flight; fetching
npm verb request uri https://registry.npmjs.org/cordova
npm verb request no auth needed
npm info attempt registry request try #1 at 16:47:06
npm verb request id 62f85abc5c5b7cd5
npm verb etag "6KQ69KRX02Y8MUJFT56H9DE6N"
npm http request GET https://registry.npmjs.org/cordova
npm info retry will retry, error on last attempt: Error: self signed certificate in certificate chain
As you can see from log, npm run version 2.14.12 and it complains that the cause is a self signed certificate - likely issued by https://registry.npmjs.org/cordova. So, to overcome this issue, I run
npm config set registry=http://registry.npmjs.org
And, after that (just the relevant part)
C:\Users\ferrero>npm install -g cordova
npm verb cache add spec cordova
npm verb addNamed "latest" is being treated as a dist-tag for cordova
npm info addNameTag [ 'cordova', 'latest' ]
npm verb addNameTag registry:http://registry.npmjs.org/cordova not in flight; fetching
npm verb request uri http://registry.npmjs.org/cordova
npm verb request no auth needed
npm info attempt registry request try #1 at 16:59:34
npm verb request id 359f93cb3aa8b76e
npm verb etag "6KQ69KRX02Y8MUJFT56H9DE6N"
npm http request GET http://registry.npmjs.org/cordova
npm http 304 http://registry.npmjs.org/cordova
npm verb headers {
date: 'Tue, 26 Jan 2016 18:59:34 GMT',
npm verb headers via: '1.1 varnish',
npm verb headers 'cache-control': 'max-age=300',
npm verb headers etag: '"6KQ69KRX02Y8MUJFT56H9DE6N"',
npm verb headers age: '263',
npm verb headers connection: 'keep-alive',
npm verb headers 'x-served-by': 'cache-atl6230-ATL',
npm verb headers 'x-cache': 'HIT',
npm verb headers 'x-cache-hits': '1',
npm verb headers 'x-timer': 'S1453834774.362657,VS0,VE1',
npm verb headers vary: 'Accept'
}
npm verb etag http://registry.npmjs.org/cordova from cache
npm verb get saving cordova to C:\Users\ferrero\AppData\Roaming\npm-cache\registry.npmjs.org\cordova\.cache.json
npm verb addNamed "5.4.1" is a plain semver version for cordova
npm verb addRemoteTarball http://registry.npmjs.org/cordova/-/cordova-5.4.1.tgz
not in flight; adding
npm verb addRemoteTarball [ 'http://registry.npmjs.org/cordova/-/cordova-5.4.1.tgz',
npm verb addRemoteTarball 'bc56bc1d3c5387a7926408212dfbce59002f9d76' ]
This time, it does not complain anything else. Instead, the loading indicator - a pipe character - keep running and running. So, what should i do in order to download such dependency ?
We seem to be looking at two distinct issues here.
The certificate error is likely due to an outbound SSL proxy. Someone, most likely your employer, is opening all SSL traffic on the way out. To fix it, you'll need to tell NPM that this certificate is okay by importing the CA certificate of the proxy in use.
npm config set cafile = "/the/certificate/file.pem"
You may also need to set the proxy address for npm as well:
npm config set proxy http://proxy.example.com:3128
npm config set https-proxy http://proxy.example.com:3128
The incompatibility with node 5.0 seems to have been fixed according to my research. The documentation just seems to be out of date.
The bug in Cordova which may have been the issue was a missing method in the Q promises library, which Cordova depends upon.
In November 2015 a user was able to use Ionic successfully with node 5.1.0.
Even i faced same issue while doing any npm install -g XXX command, it was resolved by npm config set strict-ssl false
Ok, I think the note about node 4 vs node 5 is from the old days of cordova 5.0 when there was a problem when installing cordova with node 5.
Since then they released cordova 5.4 and cordova 6 where there is no more issue with node 5.
I usually don't use ionic, but to be sure, with my fresh install of node v5.4.1, where I already was running cordova 5.4 (installed also with node 5.4.1), I:
installed cordova 6 : npm install -g cordova
installed ionic 1.7.13 : npm install -g ionic
created a ionic app : ionic start myApp tabs
run the app on an android device
cd myApp
cordova platform add android
ionic run android
And everything worked perfectly.
So I assume that you can safely try to install the latest version of node to build apps with ionic.
And maybe node 5.4.1 will solve the issue you face with node 4.2.4?
Problem here it that you are using self-signed certificate according to error self signed certificate in certificate chain.
If you want to fix the error here some info for you:
How to fix SSL certificate error when running Npm on Windows?
https://confluence.atlassian.com/display/SOURCETREEKB/Resolving+SSL+Self-Signed+Certificate+Errors
But if there is no way to deal with problem just set http registry(carry about config word)
npm config set registry http://registry.npmjs.org/
A similar thing happened to me before and what worked for me back then was.
First, uninstall node and npm.
Second, delete npm and npm-cache folders on C:\Users\yourname\AppData\Roaming.
And lastly, redownload and reinstall a fresh copy of node.js.
I'm not sure if this is gonna work on your case but hope this helps!!

npm not installing tar package from cache when forced

I'm using Node v5.0.0 and npm v3.3.6 and running into a very isolated issue with he tar package. Due to corporate firewalls I was forced to clone the Git repository and install it from that
My problem is that despite forcing npm to install packages from the cache, tar is the only package that insists on downloading it from npm's registry.
$ npm install tar#2.2.1 --verbose --cache-min=999999999999
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'install',
npm verb cli 'tar#2.2.1',
npm verb cli '--verbose',
npm verb cli '--cache-min=999999999999' ]
npm info using npm#3.3.6
npm info using node#v5.0.0
npm verb get http://registry.npmjs.org/tar not expired, no request
npm verb cache add spec tar#2.2.1
npm verb addNamed "2.2.1" is a plain semver version for tar
npm verb addNameVersion registry:http://registry.npmjs.org/tar not in flight; fetching
npm verb get http://registry.npmjs.org/tar not expired, no request
npm verb addRemoteTarball http://registry.npmjs.org/tar/-/tar-2.2.1.tgz not in flight; adding
npm verb addRemoteTarball [ 'http://registry.npmjs.org/tar/-/tar-2.2.1.tgz',
npm verb addRemoteTarball '8e4d2a256c0e2185c6b18ad694aec968b83cb1d1' ]
npm info retry fetch attempt 1 at 8:38:23 AM
npm info attempt registry request try #1 at 8:38:23 AM
npm http fetch GET http://registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm verb request id b8672d43f7b2c569
npm http fetch 503 http://registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm info retry will retry, error on last attempt: Error: server error 503
I've double checked my cache and can see that tar v2.2.1 is in fact present and functional.
$ npm cache list | grep 'tar\\2.2.1'
~\AppData\Roaming\npm-cache\tar\2.2.1
~\AppData\Roaming\npm-cache\tar\2.2.1\package
~\AppData\Roaming\npm-cache\tar\2.2.1\package.tgz
~\AppData\Roaming\npm-cache\tar\2.2.1\package\package.json
For what it's worth, I'm able to overcome this issue by simply adding the project's Git repository in my dependencies folder and use npm install deps/node-tar before doing npm install. Still doesn't explain the problem at hand, however.

Resources