NPM Electron stuck or large package download Fail

I was trying to install electronjs via npm multiple times and each attempt takes hours and end with error. I try searching for another workaround like downloading electron from github directly but my download speed seems slow on github when i try to download electron release specifically.

prerhaps your 'npm install' stuck at node install.js:

> electron@8.0.0 postinstall
.../node_modules/electron
> node install.js

Your error probabbly looks like this or similar:

(node:3039) UnhandledPromiseRejectionWarning: HTTPError: Response code 404 (Not Found)
    at EventEmitter.emitter.on.response (/node_modules/got/source/as-stream.js:35:24)
    at EventEmitter.emit (events.js:189:13)
    at module.exports (/node_modules/got/source/get-response.js:22:10)
    at ClientRequest.handleResponse (/node_modules/got/source/request-as-event-emitter.js:155:5)
    at Object.onceWrapper (events.js:277:13)
    at ClientRequest.emit (events.js:194:15)
    at ClientRequest.origin.emit.args [as emit] (/node_modules/@szmarczak/http-timer/source/index.js:37:11)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at TLSSocket.socketOnData (_http_client.js:442:20)
(node:3039) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3039) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Aborted

But there are no problem when downloading other file and i notice that other file that i download is smaller than electron release which is about 63MB.

Apparently, github limits download speed for country ouside US and i'm not sure whether it's at sepcific time or not. And npm registry is simply point to the github release tag and that explain why my npm install always fail. Finally i found the solution and cut my install time from infinite to about 14 minutes.

Symptoms

  • slow or fail npm install
  • slow and fail github release direct download

Skip the story and show me

  • Why: to download large package or github release or repo and you are outside US
  • npm registry simply pass the URL of the release tag from the package repo on github
  • github seems to limit the download speed to about 50kbps to country outside US

Steps

  1. Do yourself a favor and google for US free proxy provider that is good and fast enough.
  2. Test and verify with your network setting if the proxy is usable and fast enough.
# add sudo if necessary
# free proxy usually is an IP Address (eg: 173.23.44.12:3128)
npm config set proxy http://PROXY.COM.EXAMPLE:PORT
npm config set https-proxy http://PROXY.COM.EXAMPLE:PORT

# add this if you got SSL certificate error
npm config set strict-ssl false

Cleanup after you finish

  • because free proxy usually expire, and you probably need to get a new one tomorrow
# remove npm proxy config
npm config rm https-proxy
npm config rm proxy
npm config rm strict-ssl

Github Direct Download

Set the proxy to your OS proxy mananger and remove it after finish download the package or release:

# these are not a code
On Mac:
Network preferences > Advanced > Proxies > Select Web Proxy (HTTP) and `secure web proxy (HTTPS)`

On Windows 10:
Settings > Manual Proxy Settings > Make sure `Used a proxy server` is On

Footnote:

  • this slow download speed does not happen all the time, sometimes it pretty fast like 4 minutes to complete the download.
  • don't browse or login any services when you are using the free proxy for security purposes.
  • Some site might detect you as suspicious because this proxy address usually are used by web scrapper.