7

I have a problem with the auto-update of electron app, After I finished all the app parts and I am trying to push it to my custom update server , I found this error message in my logger :

Error unknown ENOENT: no such file or directory, open 
'C:\{appPath}\{appName}\resources\app-update.yml'

and here is my package.json build configuration

"build": {
    "appId": "com.server.app",
    "copyright": "Copyright company name",
    "generateUpdatesFilesForAllChannels": true,
    "win": {
      "target": "nsis",
      "icon": "build/icon.ico"
    },
    "mac": {
      "target": "dmg",
      "artifactName": "appName.dmg",
      "icon": "build/icon.icns"
    },
    "dmg": {
      "background": "build/i-bg.tif",
      "icon": "build/setup.icns",
      "iconSize": 80,
      "title": "${productName}-${version}",
      "window": {
        "width": 540,
        "height": 380
      }
    },
    "nsis": {
      "artifactName": "${productName}-Setup-${version}.${ext}",
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true,
      "installerIcon": "build/setup.ico",
      "uninstallerIcon": "build/setup.ico",
      "installerHeader": "build/installerHeader.bmp",
      "installerSidebar": "build/installerSidebar.bmp",
      "runAfterFinish": true,
      "deleteAppDataOnUninstall": true,
      "createDesktopShortcut": "always",
      "createStartMenuShortcut": true,
      "shortcutName": "AppName",
      "publish": [{
        "provider": "generic",
        "url": "https://my-update-server/path"
      }]
    },
    "extraFiles": [
      "data",
      "templates"
    ]
  },
  "publish": [{
    "provider": "generic",
    "url": "https://my-update-server/path"
  }],

and here is the code for triggering the auto-update

//-----------------------------------------------
// Auto-Update event listening 
//-----------------------------------------------

autoUpdater.on('checking-for-update', () => {
  splashLoadingStatus(`Checking for ${appName} update ...`);
})

autoUpdater.on('update-available',(info) => {
  splashLoadingStatus(`${appName} new update available.`);
})

autoUpdater.on('update-progress',(progInfo) => {
  splashLoadingStatus(`Download speed: ${progInfo.bytesPerSecond} - Download ${progInfo.percent}% (${progInfo.transferred}/${progInfo.total})`);
})

autoUpdater.on('error' , (error) => {
  dialog.showErrorBox('Error', error.message);
})

autoUpdater.on('update-downloaded', (info) => {
  const message = {
    type: 'info',
    buttons: ['Restart', 'Update'],
    title: `${appName} Update`,
    detail: `A new version has been downloaded. Restart ${appName} to apply the updates.`
  }

  dialog.showMessageBox(message, (res) => {
    if(res === 0) {
      autoUpdater.quitAndInstall();
    }
  })
})
.....
          autoUpdater.setFeedURL('https://my-update-server/path');
          autoUpdater.checkForUpdatesAndNotify();
.....

then when I am pushing the build it will do everything correct with the latest.yml file generating but after installing I found the app-update.yml is not there ...

Mohamed Maher
  • 163
  • 1
  • 10
  • Did you ever found a solution to this? – HelloWorld May 30 '21 at 18:19
  • Were you able to solve this problem? I have the same problem. – Mehrshad Farzaneh Aug 17 '21 at 23:00
  • Since OP has gone AWOL, @MehrshadFarzaneh and @HelloWorld, I solved this issue by simplifying things as much as possible, including the `npm` command + params, and the config files / sections. In my case, the issue was that I had some config in the `package.json` and some more in a separate json file, and depending on how I invoked npm, I got different results. – Caio Campos Sep 30 '21 at 03:25

2 Answers2

2

If you have a problem with missing app-update.yml and dev-app-update.yml then paste the following code into index.js:

import path from "path"
import fs from "fs"
const feed = 'your_site/update/windows_64'

let yaml = '';

yaml += "provider: generic\n"
yaml += "url: your_site/update/windows_64\n"
yaml += "useMultipleRangeRequest: false\n"
yaml += "channel: latest\n"
yaml += "updaterCacheDirName: " + app.getName()

let update_file = [path.join(process.resourcesPath, 'app-update.yml'), yaml]
let dev_update_file = [path.join(process.resourcesPath, 'dev-app-update.yml'), yaml]
let chechFiles = [update_file, dev_update_file]

for (let file of chechFiles) {
    if (!fs.existsSync(file[0])) {
        fs.writeFileSync(file[0], file[1], () => { })
    }
}
1

I fixed it by using autoUpdater.setFeedURL() before autoUpdater.checkForUpdates(). Below is the code snippet that works for github releases. Also, please make sure there is existing release in Github before running this code.

import { autoUpdater } from "electron-updater";

// ...

autoUpdater.setFeedURL({
  provider: "github",
  owner: "org",
  repo: "repo",
});
Hanzla Mateen
  • 96
  • 1
  • 4