electron: Cannot install behind corporate firewall

Windows 7:

C:\electron\project\node_modules\electron\install.js:47
  throw err
  ^

Error: unable to get local issuer certificate
    at TLSSocket.<anonymous> (_tls_wrap.js:1088:38)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:188:7)
    at TLSSocket._finishInit (_tls_wrap.js:610:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38)

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 9
  • Comments: 31 (4 by maintainers)

Most upvoted comments

Have you tried with npm config set strict-ssl false? Im also using a corporate proxy and that worked for me.

export NODE_TLS_REJECT_UNAUTHORIZED=0 Worked for me

We recommend you utilize external tools available to you to properly configure your proxy, or do something like npm config set strict-ssl false. At present, this isn’t something for which the optimal solution presents itself as a change to Electron itself.

@codebytere - thank you, we have moved away from trying Electron and went with nwjs. It is just not possible to use Electron in our environment.

To specifically address your suggestions: 1) I can’t change the proxy configuration. It is configured correctly as required by corporate policy. 2) npm works just fine because I have the strict-ssl setting. The issue is the Electron post install script and it cannot be addressed by npm.

Also for me it’s not fixed. trying to download electron 9.0.2 specified an cafile and set the strict-ssl option to false. always getting the electron post install error

> node install.js RequestError: unable to get local issuer certificate at ClientRequest. (C:\Users\userName\Downloads\projectName\packager-test\node_modules\got\source\request-as-event-emitter.js:178:14) at Object.onceWrapper (events.js:422:26) at ClientRequest.emit (events.js:327:22) at ClientRequest.origin.emit (C:\Users\userName\Downloads\projectName\packager-test\node_modules\@szmarczak\http-timer\source\index.js:37:11) at TLSSocket.socketErrorListener (_http_client.js:432:9) at TLSSocket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:84:8) at processTicksAndRejections (internal/process/task_queues.js:84:21)

EDIT: SOLVED by: set NODE_EXTRA_CA_CERTS=/path/to/issuer/.crt

specify the node_extra_ca_certs for nodejs before downloading electron solved the problem.

Why closed? this issue hasn’t been resolved. I am still getting same issue.

Can you try

ELECTRON_GET_USE_PROXY=1

GLOBAL_AGENT_HTTPS_PROXY=http://localhost:8888
GLOBAL_AGENT_HTTP_PROXY=http://localhost:8888

http-proxy=http://localhost:8888
proxy=http://localhost:8888
HTTP_PROXY=http://localhost:8888
HTTPS_PROXY=http://localhost:8888
NODE_TLS_REJECT_UNAUTHORIZED=0

Not all of them might be required.

ref https://www.electronjs.org/docs/tutorial/installation#proxies

(replace http://localhost:8888 with your own proxy)

Similar issue here. We have an npm cache using aritfactory - that is: We usually do not use the official npm registry but our local one. We have to do this because our corporate proxy needs authentication.

Of course this won’t work as long as the post-install script tries to download something itself.

Hard coding the proxy credentials in the configuration file for my local PC is bad. Doing this in our CI system is impossible. I currently see two options:

  1. Package everything into npm packages, don’t do any download in the post-install script
  2. Somehow use the system proxy setting (don’t know if this is possible from within the post-install script)
  3. Probably it’d be somehow possible to let electron-download (assuming that this is used to install electron) take the electron package from some local file share?

PS.: We’re currently working on Windows7

EDIT: Simply setting $env:NODE_TLS_REJECT_UNAUTHORIZED=0 before the electron install ended up working. Then even after setting it back to 1, everything works as normal. But I will leave my original workaround below in case it still helps someone.

For anyone who is still struggling with this issue, I found a workaround on Windows:

  • run npm install electron on a computer which is not behind the problematic proxy/firewall.
  • copy the ‘electron’ folder from node_modules and transfer it to the computer with your electron project. store it somewhere safe and easy to get to as you may need it more than once. (this may raise eyebrows with your IT department, but the fact that VSCode, Microsoft Teams, and Slack are all built on electron should put them at ease - mine trusts me.)
  • in your electron project, run $env:ELECTRON_SKIP_BINARY_DOWNLOAD=1; npm install. This will install everything except it won’t try to download the electron binary. at this point your project will crash when electron tries to start.
  • drag your stashed electron folder into the node_modules folder and overwrite the incomplete one in there. Then your project works.

The problem now is, each time I run npm install or npm add even just for a single new package, it re-runs the electron postinstall . So I have to set $env:ELECTRON_SKIP_BINARY_DOWNLOAD=1 but then npm install will still overwrite my electron installation with an incomplete one and I have to replace the electron folder again.

So now I’m looking for a workaround for that. I may have to split my web app into its own project and have electron in a separate project that just imports everything and bootstraps the web app in an electron window…

Everyone, this is not an Electron issue. NPM/Electron cannot connect to some external URL through your corporate proxy server, because it doesn’t trust your corporate proxy’s root certificates. If you are on a team then probably they already have a guide for how to set it up, ask your IT or team leader about it.

DO NOT set NODE_TLS_REJECT_UNAUTHORIZED=0 this is insecure. You should not be connecting to servers with untrusted CAs. This setting is there to protect you from downloading insecure or unverified packages. Everyone has heard this a million times and still people do it because it’s easier. If you’re using this, every time you install or update a package it puts your project at risk.

@h3llsing You need root CA certificates…someone in IT or sth will know what they are. You can maybe check them in your Windows cert store (Trusted Root Certification Authorities) but it’s probably easier to ask some senior team member. From Windows cert store you can export each root cert as .crt (not PEM or DER) and then proceed as below. We have several root CAs for different levels of security, so I setup NPM to trust all of them:

Windows command line:

type rootCA1.crt > C:\Users\YOUR_USER\AppData\Roaming\npm\corpCAchain.crt
type rootCA2.crt >> C:\Users\YOUR_USER\AppData\Roaming\npm\corpCAchain.crt
type rootCA3.crt >> C:\Users\YOUR_USER\AppData\Roaming\npm\corpCAchain.crt
set NODE_EXTRA_CA_CERTS="C:\Users\YOUR_USER\AppData\Roaming\npm\corpCAchain.crt"

If you have VS Code open, close and re-open after changes (need to do this for PATH setting)

At this point everything should work, because NPM and Electron will trust your corporate certs defined in NODE_EXTRA_CA_CERTS variable.

If it doesn’t work, you can try defining your corporate proxy URLs for Node to use:

http_proxy=http://proxy-url
https_proxy=http://proxy-url
HTTP_PROXY=http://proxy-url
HTTPS_PROXY=http://proxy-url
no_proxy="some-company-url,some-company-url-2" (necessary if you will be installing packages from company servers)
NO_PROXY="some-company-urls,some-company-url-2" (necessary if you will be installing packages from company servers)
registry=https://registry.npmjs.org/

If you connect manually to a corporate VPN, when you are connected/disconnected you will need to CHANGE your http_proxy & https_proxy to use the required URL.

So ex. we have locally installed proxy with one URL, and VPN proxy with another URL. If you have static URL set in Windows proxy settings, this is probably the URL you want. If you have a script in there then you’ll need a different proxy URL at different times, based on some conditions the script is checking (ie. if you’re connected to VPN or not). Make sure you don’t copy the proxy script address and try to use it as the proxy URL.

If, after everything, it still doesn’t work, maybe your corporate proxy is blocking the traffic. Make sure you as a user have the rights to use NPM.

export NODE_TLS_REJECT_UNAUTHORIZED=0 Worked for me

Works.