Make debugging easy. Make programming fun (again). Plus lots of high quality content on marketing, sales and lifestyle for anyone looking to expand their thinking.

Friday, June 30, 2017

[SOLVED] - npm install crashes with error code 128

Error scenario:

You are trying to run npm install on an existing git repository, but your npm install stops somewhere at fetchMetadata and throws an error code 128, which doesn't tell you much.

First of all, there are multiple possible causes for error code 128, most of them have something to do with permissions, so make sure you have access permissions and you're using proper ssh key(if any).

However, if that doesn't solve the problem, you might try this:
Try to split the package.json file's dependency list into N subgroups and run npm install on those chunks.

This way, it will download some packages every time, and it won't download them anymore when you run npm install for the next chunk.

I'm not sure what's root cause of this bug, but it seems to be a potential bug in npm v.5.0.0+. This needs some more research, but for the moment, I hope that the trick of splitting the npm install load will do the trick for you!

This was tested with node v8.0.0.0 and v8.1.3 with npm v5.0.0 and v5.1.3.
OS: Ubuntu 16.04
(nvm was used as the node manager, and the package.json contained both free and private git repos hosted at bitbucket and github).

UPDATE:
Possible reason for this error is the too high number of connections npm is trying to open. For some internet routers / connections, it might simply be too much. Currently, there's no official ability to limit max connections from npm, even there were some discussions on this in past. Lets hope this will be added into the newer versions.

Also, npm's error log is very bad at reporting the root cause of this error. In most cases, it simply says error code 128. However, every once in a while, it will print out something like Connection refused, or cannot connect to remote repository - host unknown, or something.

This error has a tendency to show up at large repos , filled with lots of git+ssh entries.

This issue might be somewhat related to this problem too:
https://github.com/npm/npm/issues/7862