How does npm handle lock files - node.js

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.

Related

npm install gifsicle behind corporate proxy failed or stuck at windows system

windows 7,
npm#3.10.3,
node#v6.7.0
npm and git are set up for using the corporate proxy.
It took me a while to figure out how git and npm can use the corporate proxy, luckily it was successful done.
npm config file (.npmrc) looks like:
strict-ssl=false
proxy=http://domain%5Cmyname:mypassword#corporateproxy:8088/
http-proxy=http://domain%5Cmyname:mypassword#corporateproxy:8088/
https-proxy=http://domain%5Cmyname:mypassword#corporateproxy:8088/
cache-lock-wait=30000
cache-lock-retries=10
cache-lock-stale=300000
start installation
npm install gifsicle --verbose
and here is the logging:
C:\temp\2018_0110\estatico>npm install gifsicle --verbose
npm info it worked if it ends with ok
npm verb cli [ 'C:\\temp\\TOOLS\\PortableNode\\node.exe',
npm verb cli 'C:\\temp\\TOOLS\\PortableNode\\node_modules\\npm\\bin\\npm-cli.j
s',
npm verb cli 'install',
npm verb cli 'gifsicle',
npm verb cli '--verbose' ]
npm info using npm#3.10.3
npm info using node#v6.7.0
npm verb request uri https://registry.npmjs.org/gifsicle
npm verb request no auth needed
npm info attempt registry request try #1 at 09:00:29
npm verb request id 7014dcca318052d1
npm verb etag "5a108ad8-73b8"
npm verb lastModified Sat, 18 Nov 2017 19:32:40 GMT
npm http request GET https://registry.npmjs.org/gifsicle
npm http 304 https://registry.npmjs.org/gifsicle
npm verb headers { date: 'Wed, 17 Jan 2018 08:00:14 GMT',
npm verb headers via: '1.1 varnish',
npm verb headers 'cache-control': 'max-age=300',
npm verb headers etag: '"5a108ad8-73b8"',
npm verb headers age: '13585',
npm verb headers connection: 'close',
npm verb headers 'x-served-by': 'cache-hhn1546-HHN',
npm verb headers 'x-cache': 'HIT',
npm verb headers 'x-cache-hits': '10',
npm verb headers 'x-timer': 'S1516176014.461012,VS0,VE0',
npm verb headers vary: 'Accept-Encoding, Accept' }
npm verb etag https://registry.npmjs.org/gifsicle from cache
npm verb get saving gifsicle to C:\Users\MYUSERHOME\AppData\Roaming\npm-cach
e\registry.npmjs.org\gifsicle\.cache.json
npm verb correctMkdir C:\Users\MYUSERHOME\AppData\Roaming\npm-cache correctM
kdir not in flight; initializing
npm verb cache add spec gifsicle
npm verb addNamed "latest" is being treated as a dist-tag for gifsicle
npm info addNameTag [ 'gifsicle', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/gifsicle not in flight;
fetching
npm verb get https://registry.npmjs.org/gifsicle not expired, no request
npm verb addNamed "3.0.4" is a plain semver version for gifsicle
npm verb afterAdd C:\Users\MYUSERHOME\AppData\Roaming\npm-cache\gifsicle\3.0
.4\package\package.json not in flight; writing
npm verb correctMkdir C:\Users\MYUSERHOME\AppData\Roaming\npm-cache correctM
kdir not in flight; initializing
npm verb afterAdd C:\Users\MYUSERHOME\AppData\Roaming\npm-cache\gifsicle\3.0
.4\package\package.json written
npm verb correctMkdir C:\Users\MYUSERHOME\AppData\Roaming\npm-cache\_locks c
orrectMkdir not in flight; initializing
npm verb lock using C:\Users\MYUSERHOME\AppData\Roaming\npm-cache\_locks\sta
ging-fdad36d07e8f1a67.lock for C:\temp\2018_0110\estatico\node_modules\.staging
npm verb unbuild node_modules\.staging\gifsicle-c326b995
npm verb gentlyRm don't care about contents; nuking C:\temp\2018_0110\estatico\n
ode_modules\.staging\gifsicle-c326b995
npm verb tar unpack C:\Users\MYUSERHOME\AppData\Roaming\npm-cache\gifsicle\3
.0.4\package.tgz
npm verb tar unpacking to C:\temp\2018_0110\estatico\node_modules\.staging\gifsi
cle-c326b995
npm verb gentlyRm don't care about contents; nuking C:\temp\2018_0110\estatico\n
ode_modules\.staging\gifsicle-c326b995
npm verb gentlyRm don't care about contents; nuking C:\temp\2018_0110\estatico\n
ode_modules\.staging\gifsicle-c326b995\node_modules
npm info lifecycle gifsicle#3.0.4~preinstall: gifsicle#3.0.4
npm info linkStuff gifsicle#3.0.4
npm verb linkBins gifsicle#3.0.4
npm verb link bins [ { gifsicle: 'cli.js' },
npm verb link bins 'C:\\temp\\2018_0110\\estatico\\node_modules\\.bin',
npm verb link bins false ]
npm verb linkMans gifsicle#3.0.4
npm info lifecycle gifsicle#3.0.4~install: gifsicle#3.0.4
npm info lifecycle gifsicle#3.0.4~postinstall: gifsicle#3.0.4
> gifsicle#3.0.4 postinstall C:\temp\2018_0110\estatico\node_modules\gifsicle
> node lib/install.js
1.) installation stuck for a long time at the gifsicle#3.0.4 postinstall script 'node lib/install.js'.
2.)15 min or more later next message
‼ tunneling socket could not be established, cause=read ECONNRESET
‼ gifsicle pre-build test failed
i compiling from source
3.) last message
× RequestError: tunneling socket could not be established, cause=socket hang u
p
at ClientRequest.<anonymous> (C:\temp\2018_0110\estatico\node_modules\got\in
dex.js:74:21)
at ClientRequest.g (events.js:291:16)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at ClientRequest.onError (C:\temp\2018_0110\estatico\node_modules\caw\node_m
odules\tunnel-agent\index.js:178:21)
at ClientRequest.g (events.js:291:16)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:308:9)
at emitOne (events.js:96:13)
npm verb lifecycle gifsicle#3.0.4~postinstall: unsafe-perm in lifecycle true
npm verb lifecycle gifsicle#3.0.4~postinstall: PATH: C:\temp\TOOLS\PortableNode\
node_modules\npm\bin\node-gyp-bin;C:\temp\2018_0110\estatico\node_modules\gifsic
le\node_modules\.bin;C:\temp\2018_0110\estatico\node_modules\.bin;C:\temp\TOOLS\
PortableNode;C:\temp\TOOLS\PortableNode;C:\temp\TOOLS\PortableGit\cmd;C:\Program
Files (x86)\MQSeries Client\Java\lib;C:\ProgramData\Oracle\Java\javapath;C:\Win
dows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPow
erShell\v1.0\;C:\Program Files (x86)\CTV_V7_E-I\isiscomm\w3\lib;C:\Program Files
(x86)\MQSeries Client\bin64;C:\Program Files (x86)\MQSeries Client\bin;C:\Progr
am Files (x86)\MQSeries Client\tools\c\samples\bin;C:\Program Files\Citrix\Syste
m32\;C:\Program Files\Citrix\ICAService\;C:\Program Files (x86)\UltraEdit\;C:\Pr
ogram files\IBM\sqllib\bin;C:\Program files\IBM\sqllib\funtion;C:\Program Files
(x86)\Subversion;C:\Program Files\TortoiseSVN\bin;C:\Users\MYUSERHOME\.dnx\b
in;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\8.1\
Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\120\Tools\Bin
n\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\
McAfee\MOVE AV Client\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Fi
les (x86)\TAA\taaseu;C:\Program Files (x86)\UltraEdit
npm verb lifecycle gifsicle#3.0.4~postinstall: CWD: C:\temp\2018_0110\estatico\n
ode_modules\gifsicle
npm verb unlock done using C:\Users\MYUSERHOME\AppData\Roaming\npm-cache\_lo
cks\staging-fdad36d07e8f1a67.lock for C:\temp\2018_0110\estatico\node_modules\.s
taging
estatico#5.0.0 C:\temp\2018_0110\estatico
`-- gulp-imagemin#3.0.3
`-- imagemin-gifsicle#5.2.0
`-- gifsicle#3.0.4
npm verb exit [ 0, true ]
npm info ok
while installation node-gyp will be triggered and it seems that the proxy settings not used from npm.
I can successful install gifsicle at another computer and within direkt internetconnection without any issue.
Q: Has anybody successful installed gifsicle behind corporate proxy, then please tell me how it`s done?
EDIT:
This is the part where it stuck at least.
C:\temp\estatico\node_modules\gifsicle\lib>node install.js --verbose
'use strict';
var BinBuild = require('bin-build');
var log = require('logalot');
var bin = require('./');
bin.run(['--version'], function (err) {
if (err) {
log.warn(err.message);
log.warn('gifsicle pre-build test failed');
log.info('compiling from source');
var cfg = [
'./configure --disable-gifview --disable-gifdiff',
'--prefix="' + bin.dest() + '" --bindir="' + bin.dest() + '"'
].join(' ');
var builder = new BinBuild()
.src('https://github.com/kohler/gifsicle/archive/v1.88.tar.gz')
.cmd('autoreconf -ivf')
.cmd(cfg)
.cmd('make install');
return builder.run(function (err) {
if (err) {
log.error(err.stack);
return;
}
log.success('gifsicle built successfully');
});
}
log.success('gifsicle pre-build test passed successfully');
});
To install npm packages through a firewall I found that I needed to set proxy environment variable(s) instead of using npm config. This seems to have changed a bit with different versions of npm. I currently set 'http_proxy' and 'https_proxy' and that seems to cover all npm versions I use.
I've not used gifsicle
I've faced similar issue not exactly same.npm install command for most of the packages. I am behind corporate proxy.
For this i tried many solutions it never worked.
Finally i did this,
Try to run the following command in cmd,
npm config set https-proxy "http://your_companyproxy_here:8080"
Then it will work fine.

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.

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 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.

npm hangs while trying to install gulp

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!

Resources