Search code examples
electronauto-updatesquirrel.windows

autoUpdater.setFeedURL is not a function


I'm attempting to implement windows auto update functionality in an electron app (which may lead to my early death) and I'm getting this error.

enter image description here

This is the URL I'm passing for testing purposes

EDIT: my electron app is using the two package.json structure and this code is in my app>main.js file

const feedURL = 'C:\\Users\\p00009970\\Desktop\\update_test';
autoUpdater.setFeedURL(feedURL); 
autoUpdater.checkForUpdates(); 

EDIT2: Thanks to @JuanMa, I was able to get it working. Here is the code.

// auto update functionality

const {autoUpdater} = require('electron')

// local file system example: const feedURL = 'C:\\Users\\john\\Desktop\\updates_folder';
// network file system example: const feedURL = '\\\\serverName\\updates_folder';

const feedURL = '\\\\serverName\\updates_folder';

app.on('ready', () => {
    autoUpdater.setFeedURL(feedURL);

    // auto update event listeners, these are fired as a result of  autoUpdater.checkForUpdates();

    autoUpdater.addListener("update-available", function(event) {

    });
    autoUpdater.addListener("update-downloaded", function(event,   releaseNotes, releaseName, releaseDate, updateURL) {

      //TODO: finess this a tad, as is after a few seconds of launching the app it will close without warning
      // and reopen with the update which could confuse the user and possibly cause loss of work

        autoUpdater.quitAndInstall();
    });
    autoUpdater.addListener("error", function(error) {

    });
    autoUpdater.addListener("checking-for-update", function(event) {

    });
    autoUpdater.addListener("update-not-available", function(event) {

    });

    // tell squirrel to check for updates
    autoUpdater.checkForUpdates();
})

Solution

  • Are you including the autoUpdater module correctly?

    const {autoUpdater} = require('electron')
    

    If so try to execute the code after the app 'ready' event.

    app.on('ready', () => {
      const feedURL = 'C:\\Users\\p00009970\\Desktop\\update_test';
      autoUpdater.setFeedURL(feedURL); 
      autoUpdater.checkForUpdates(); 
    })