electronelectron-packager

How can I run electron-packager offline without an Internet connection?


I have an Angular project. I want to convert it to a desktop application. For this, I use Electron.

I can run

electron .

It works fine.

But now I want to make an EXE file. 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 can I solve it?! Again, I work offline (with JFrog Artifactory) without an Internet connection.

Is there another Electron package which can do the same without an Internet connection? (make an EXE file)


Solution

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

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

    The solution is simple. When you executed:

    npm install electron
    

    A ZIP file of the binaries of Electron are cached on 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**
    

    That’s all.

    Theoretically, electron-packager has an option called "download" which you can pass to it a "cacheRoot" or "mirrorOptions" to download the electron.zip file.

    By default, you don’t need to change the cacheRoot, but unfortunately both options of the download didn’t work for me.

    BTW, mirrorOptions got an object, not a string. So it’s 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 searches a special environment variable or the mirrorOptions which I told before. If this function won’t find them, it will take the default, which is GitHub.

    A solution when you have an Artifactory repository:

    1. Create a .npmrc file in your project and write there:

      ELECTRON_MIRROR="http://my mirror site/electron/"
      

      Be aware that it ends with a backslash.

    2. Go to the package.json file, and there write to scripts:

      "pac": "electron-packager -- . --platform=win32"
      
    3. Execute it: npm run pac