Search code examples
electronelectron-packager

How to run electron-packager offline without internet?


I have an Angular project. I want to convert him to Desktop application. For this i use Electron.js.

I can run

electron . 

It works fine.

But now i want to make an exe. For this i want to use electron-packager.

The problem: I run:

electron-packager . --platform=win32

The error: getaddrinfo EAI_AGAIN github.com

I understand that electron-packager needs github, but how to solve it?! Again i work offline(with jfrog artifactory) without internet.

Is there another electron package which can do the same without internet? (make an exe)


Solution

  • The problem is that electron-packager go to github.com to download electron.js.

    So as @Alexander Leithner said to use electronZipDir option. (and also malept in electron channel in Discord)

    The solution is simple, when you executed:

    npm install electron
    

    A zip file of the binaries of electron are cached in your computer.

    The command for electron-packager looks like this:

    npm install  -D electron-packager
    npx electron-packager  .  -- platform=win32 --electronZipDir=C:/Users/baruc/AppData/Local/electron/Cache/**some long string**
    

    Thats all

    Edit 25/7/2021 Theoretically, electron-packager has an option called "download" which you can pass to him a "cacheRoot" or "mirrorOptions" to download the electron.zip file. By default you dont need to change the cacheRoot, but unfortunately both options of the download didnt work for me.

    BTW, mirrorOptions got an object, not a string. So its not clear how to pass an object from the command line.

    I saw that in the file artifact-utils.js of the @electron/get library, and there in the function called "mirrorVar" it search a special environment variables or the mirrorOptions which i tell before. If this function wont find them it will take the default which is github.

    Solution when you have an artifactory:

    1. Create in your project an .npmrc file and write there: ELECTRON_MIRROR="http://my mirror site/electron/" Be aware that it end with back slash.

    2. Go to package.json file, and there to scripts write: "pac": "electron-packager -- . --platform=win32"

    3.execute it: npm run pac