Electron-builder: Auto-updater with Amazon S3

Created on 28 Feb 2017  Â·  32Comments  Â·  Source: electron-userland/electron-builder

  • electron-builder v14.5.2

  • electron-updater v1.7.1

I'm having trouble setting the auto update process. I'm publishing my artifact on Amazon S3 correctly (and the auto-generated latest.yml as well). The folders are public.

I followed the wiki on how to implement the Auto-Updater and I see that I have the app-update.yml file in my resources folder, but when I start my application I get the

Checking for update...

message, but then I get no response about if there is an update available or not.

The latest.yml file contains the following fields:

version: 1.0.0
releaseDate: '2017-02-28T10:52:24.778Z'
githubArtifactName: my-Setup-1.0.0.exe
path: my_Setup_1.0.0.exe
sha2: 5a7459ca7bf33808e43803df72961584124ec42d28a2343d1bf62d4006c258e7

while the app-update.yml file in my resources folder contains:

provider: s3
bucket: my_bucket_name
path: path/to/my/files

The package.json looks like this:

...
"win": {
      "icon": "./img/icon.ico",
      "target": [
        "nsis"
      ],
      "publish": {
        "provider": "s3",
        "bucket": "my_bucket_name",
        "path": "path/to/my/files"
      }
    },
    "nsis": {
      "artifactName": "${productName}_Setup_${version}.${ext}",
      "installerIcon": "./img/installer_logo.ico"
    },
...

What am I doing wrong?

bug electron-updater

All 32 comments

Unfortunately that does not give much more information:

[2017-02-28 12:13:05:0000] [info] Checking for update

This is the only line in the log file.

Re-looking at the latest.yml file...is it ok that I have a field named _githubArtifactName_ even though I'm using s3 ?

is it ok that I have a field named githubArtifactName even though I'm using s3 ?

Yes. Because you can set any provider in runtime.

This is the only line in the log file.

Hmm... Is it possible for you to check is auto update works on macOS?

Please run your app in the terminal (cmd).

set DEBUG=electron-builder
path_to_your_app.exe

and attach output here.

Output on Windows, launched from cmd:

$ set DEBUG=electron-builder

$ ./dist/win-unpacked/box.exe

Wait for app ready

starting server on  /tmp/app.boxMainProcess
starting TLS server false
starting server as Unix || Windows Socket
[12:23:36:0159] [info] Checking for update


I'm trying to set up the auto update on macOS as well...I wasn't working on it yet

electron version?

electron v.1.4.5

I set up the auto update on macOS and I have the same situation...it did not upload the latest-mac.json file though, but I'm not sure if it had to since I'm using dmg as target and not zip.

electron v.1.4.5

Please upgrade to 1.4.15 or even to latest 1.6.1

Tried both v1.4.15 and v1.6.1 with no luck

I also upgraded electron-updater to v1.8.0

Now I get some output with

set DEBUG=electron-builder

$ ./dist/win-unpacked/box.exe

Wait for app ready

starting server on  /tmp/app.boxMainProcess
starting TLS server false
starting server as Unix || Windows Socket
(node:2984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:2984) 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.
(node:2984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): [object Object]
(node:2984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): [object Object]
(node:2984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): [object Object]
(node:2984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): [object Object]
(node:2984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): [object Object]


Don't know it this will help, but adding the following lines

 autoUpdater.checkForUpdates().then(
        function (val) {
            log.info('Promise fulfilled');
        }).catch(
        function (reason) {
            log.error('Handle rejected promise (' + reason + ') here.');
        });

I get this error in my logs:

ERROR Handle rejected promise (ReferenceError: sendStatus is not defined) here.

@dventurino Cool. Could you please change

log.error('Handle rejected promise (' + reason + ') here.');

to log.error('Handle rejected promise (' + reason.stack || reason + ') here.');

Yep!

INFO Checking for update
ERROR Handle rejected promise (ReferenceError: sendStatus is not defined
    at NsisUpdater.autoUpdater.on (C:\Users\Daniele\git\box\dist\win-unpacked\resources\app.asar\main.js:228:5)
    at emitNone (events.js:86:13)
    at NsisUpdater.emit (events.js:185:7)
    at C:\Users\Daniele\git\box\dist\win-unpacked\resources\app.asar\node_modules\electron-updater\src\AppUpdater.ts:140:10
    at Generator.next (<anonymous>)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)
From previous event:
    at NsisUpdater._checkForUpdates (C:\Users\Daniele\git\box\dist\win-unpacked\resources\app.asar\node_modules\electron-updater\out\AppUpdater.js:191:11)
    at NsisUpdater.checkForUpdates (C:\Users\Daniele\git\box\dist\win-unpacked\resources\app.asar\node_modules\electron-updater\src\AppUpdater.ts:124:35)
    at Timeout._onTimeout (C:\Users\Daniele\git\box\dist\win-unpacked\resources\app.asar\main.js:252:17)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

@dventurino Could you please post your code where do you use updater?

autoUpdater.on('checking-for-update', () => {
    sendStatus('Checking for update...');
})
autoUpdater.on('update-available', (ev, info) => {
    sendStatus('Update available.');
})
autoUpdater.on('update-not-available', (ev, info) => {
    sendStatus('Update not available.');
})
autoUpdater.on('error', (ev, err) => {
    sendStatus('Error in auto-updater.');
})
autoUpdater.on('download-progress', (ev, progressObj) => {
    sendStatus('Download progress...');
    log.info('progressObj', progressObj);
})
autoUpdater.on('update-downloaded', (ev, info) => {
    sendStatus('Update downloaded.  Will quit and install in 5 seconds.');
    // Wait 5 seconds, then quit and install
    setTimeout(function () {
        autoUpdater.quitAndInstall();
    }, 5000)
})
// Wait a second for the window to exist before checking for updates.
setTimeout(function () {
    autoUpdater.checkForUpdates().then(
        function (val) {
            log.info('Promise fulfilled');
        }).catch(
        function (reason) {
            log.error('Handle rejected promise (' + reason.stack || error + ') here.');
        });
}, 1000);

Replacing "sendStatus" with "log.info" made it work!

Well... error in your code. It seems sendStatus is not defined.

But! AppUpdater must handle errors during emit and report it properly.

You don't need to listen all events to log. electron-updater opposite to built-in electron updater handles it for you. You can listen only required for you events.

Damn! I didn't see the function definition in the example https://github.com/iffy/electron-updater-example/blob/master/main.js.

Which part of the code above should I remove ?

@iffy I suggest to remove sendStatus to keep example as simple as possible.

Hmmm... Should we get rid of the window, too, then? Perhaps this could be fixed by renaming sendStatus to something like logStatusToWindow with a comment next to each line stating that it's not necessary. I think taking it out makes it really hard to tell what's going on. Oh, wait... I have an even better idea. I'll submit a PR in about an hour.

it really hard to tell what's going on.

Just enable logging :)

@iffy you could also keep the example as is...it was my fault not to check where the function came from

@dventurino I also didn't notice this function during review :( So, I suggest to simplify example.

Anyway, it's working now on Windows. Thank you so much for your help!

On macOS I have the same problem as in https://github.com/electron-userland/electron-builder/issues/1261 with electron-builder v14.5.2

On macOS I have the same problem as in #1261 with electron-builder v14.5.2

Do you use default target or custom?

I was using

"mac": {
     ...
     "target": [
       "dmg"
     ],
...

Removing it solved the problem. It generates a zip that I'm not gonna use though.

It generates a zip that I'm not gonna use though.

This zip is required for Squirrel.Mac. So, you must use it and it will be uploaded. Sadly, but true.

Oh, okay ;) it's no trouble! Thanks again and sorry for the off-topic.

@develar https://github.com/iffy/electron-updater-example/pull/10 shows my suggested fix. I think having the window show you what's going on will help new people, but I've separated what's actually required out from the windowing parts.

This zip is required for Squirrel.Mac. So, you must use it and it will be uploaded. Sadly, but true.

Gosh, this should be somewhere in the documentation. I've been banging my head to find why the latest-mac.json was not published when I removed the zip target.

Was this page helpful?
0 / 5 - 0 ratings