Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Feature: pass environment variables to npm #307

Open
py9mrg opened this issue Jun 16, 2020 · 0 comments
Open

Feature: pass environment variables to npm #307

py9mrg opened this issue Jun 16, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@py9mrg
Copy link

py9mrg commented Jun 16, 2020

First of all THANK YOU, this is an amazing package. None of the others I've tried either work, work as smoothly, or give as brilliant an end result. This is (a) going to make my life easier as I can write apps to give to colleagues to make their lives easier, without having to explain to them how to use R, RStudio etc, and (b) make me look waaaaay smarter than I really am!

One feature request I'd like to make is for it to be possible to pass environment variables to npm. It's a long story but my company has a very strange proxy set up and I need to be able to set the NODE_EXTRA_CA_CERTS environment variable to point to a local certificate in order to get electron to install.

I have battled long and hard with trying to do this with every .npmrc file I can find, and even setting it as an environment variable in Windows using System Properties. None of these work, for reasons way beyond me. So, I had to manually install electron first, otherwise electrify would keep failing. And the only way I could do this was by setting the environment variable within the PowerShell instance I was using - i.e. I had to do:

$Env:NODE_EXTRA_CA_CERTS="c:\users\XXX\certificate.pem"
npm install -g electron

That's not necessarily a problem now I've done it, except that I noted during building that the following warning was made by node (npm?):

electron-chromedriver@9.0.0 install C:\Users\XXX\AppData\Local\Temp\RtmpKUE6V8\My_App\node_modules\electron-chromedriver
node ./download-chromedriver.js

(node:36704) UnhandledPromiseRejectionWarning: RequestError: unable to get local issuer certificate
    at ClientRequest.<anonymous> (C:\Users\XXX\AppData\Local\Temp\RtmpKUE6V8\My_App\node_modules\got\source\request-as-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:417:26)
    at ClientRequest.emit (events.js:322:22)
    at ClientRequest.origin.emit (C:\Users\XXX\AppData\Local\Temp\RtmpKUE6V8\My_App\node_modules\@szmarczak\http-timer\source\index.js:37:11)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:310:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:36704) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:36704) [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.

I'm not really sure how the install of electron-chrome driver worked without the certificate, electron itself doesn't! But my concern is that - according to the warning - soon this is going to turn into an error rather than a warning. The problem is that the process requires the installation of electron-chromedriver and I don't think installing it globally first, like I did with electron itself, will work.

I think I will need to be able to tell electrify to set the environment variable within the (I guess?) cmd/PowerShell instance it uses to do all the npm and node commands, as I did above. I am assuming that will get rid of the warning/soon to be error. I mean, that is a bit of an assumption as I assume that environment variable being set will affect the node command above as for npm or that npm is calling the node command? Would this be possible to add as an option in electrify/run_build_release? If it's trivial I don't mind having a go at a PR, but my nodejs skills, as you can probably tell, are zero so you might have to point me at the solution.

@chasemc chasemc added the enhancement New feature or request label Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants