Javascript 错误:无法读取属性';updaterCacheDirName';未定义的

Javascript 错误:无法读取属性';updaterCacheDirName';未定义的,javascript,html,electron,electron-builder,electron-updater,Javascript,Html,Electron,Electron Builder,Electron Updater,我正在尝试使用自动更新创建应用程序,但在运行版本搜索时出错 应用程序找到了版本,当它即将下降时,我得到了这个错误 Error: TypeError: Cannot read property 'updaterCacheDirName' of undefined at NsisUpdater.getOrCreateDownloadHelper (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.j

我正在尝试使用自动更新创建应用程序,但在运行版本搜索时出错

应用程序找到了版本,当它即将下降时,我得到了这个错误

Error: TypeError: Cannot read property 'updaterCacheDirName' of undefined
    at NsisUpdater.getOrCreateDownloadHelper (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:659:55)
    at async NsisUpdater.executeDownload (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:708:36)
TypeError: Cannot read property 'updaterCacheDirName' of undefined
    at NsisUpdater.getOrCreateDownloadHelper (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:659:55)
    at async NsisUpdater.executeDownload (C:\Users\neyun\Desktop\app\node_modules\electron-updater\out\AppUpdater.js:708:36)
我已经检查了我的代码,它在哪里执行更新功能,我在Github的存储库中与其他代码进行了检查,但所有代码都与我的代码相同这是我在应用程序菜单中的代码

const { app, BrowserWindow, ipcMain } = require('electron');
          const { autoUpdater } = require("electron-updater");
          let token = "";
          let v = app.getVersion()
          autoUpdater.allowPrerelease = true;
          autoUpdater.currentVersion = v;
          autoUpdater.logger = log;
          autoUpdater.autoDownload = false
          autoUpdater.setFeedURL({
            "provider": "github",
            "owner": "",
            //"token": token, //deleted 
            "private":true,
            "repo": ""
          });
          autoUpdater.logger.transports.file.level = 'info';
          log.info('App starting...');
          function createWindow () {
            mainWindow = new BrowserWindow({
              width: 800,
              height: 600,
              webPreferences: {
                nodeIntegration: true,
              },
            });
            mainWindow.loadURL(`file://${__dirname}/public/update.html`);
            mainWindow.setMenu(null)
            mainWindow.on('closed', function () {
              mainWindow = null;
            });
            autoUpdater.checkForUpdates();



          }


          createWindow();



          app.on('window-all-closed', function () {
            if (process.platform !== 'darwin') {
              app.quit();
            }
          });

          app.on('activate', function () {
            if (mainWindow === null) {
              createWindow();
            }
          });

          ipcMain.on('app_version', (event) => {
            event.sender.send('app_version', { version: app.getVersion() });
          });

          autoUpdater.on('update-available', () => {
            mainWindow.webContents.send('update_available');
            autoUpdater.downloadUpdate().then((path)=>{
              console.log('download path', path)
            }).catch((e)=>{
              console.log(e)
            })
          });

          autoUpdater.on('update-downloaded', () => {
            autoUpdater.autoInstallOnAppQuit()
          });
          autoUpdater.on('checking-for-update', () => {
            mainWindow.webContents.send('check_update');
          });
          autoUpdater.on('update-not-available', () => {
            mainWindow.webContents.send('not_update');
          });
          ipcMain.on('restart_app', () => {


          });
这是html,无论是否有新版本,都会显示版本和警告

<!DOCTYPE html>
<head>
  <title>Update</title>
  <style>
    body {
      box-sizing: border-box;
      margin: 0;
      padding: 20px;
      font-family: sans-serif;
      background-color: #eaeaea;
      text-align: center;
    }
    #notification {
      position: fixed;
      bottom: 20px;
      left: 20px;
      width: 200px;
      padding: 20px;
      border-radius: 5px;
      background-color: white;
      box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
    }
    .hidden {
      display: none;
    }
  </style>
</head>
<body>
  <h1>app</h1>
  <span><p>Version:</p> <p id="version"></p></span>
  <div id="notification" class="hidden">
    <p id="message"></p>

    <button id="close-button" onClick="closeNotification()">
      Close
    </button>
    <button id="restart-button" onClick="restartApp()" class="hidden">
      Restart
    </button>
  </div>
  <script>
    const { ipcRenderer } = require('electron');
    const version = document.getElementById('version');
    const notification = document.getElementById('notification');
    const message = document.getElementById('message');
    const restartButton = document.getElementById('restart-button');

    ipcRenderer.send('app_version');
    ipcRenderer.on('app_version', (event, arg) => {
      ipcRenderer.removeAllListeners('app_version');
      version.innerText = 'Version ' + arg.version;
    });
    ipcRenderer.on('update_available', () => {
      ipcRenderer.removeAllListeners('update_available');
      message.innerText = 'A new update is available. Downloading now...';
      notification.classList.remove('hidden');
    });
    ipcRenderer.on('check_update', () => {
      ipcRenderer.removeAllListeners('check_update');
      message.innerText = 'Looking for update...';
      notification.classList.remove('hidden');
    });
    ipcRenderer.on('not_update', () => {
      ipcRenderer.removeAllListeners('not_update');
      message.innerText = 'update not available...';
      notification.classList.remove('hidden');
    });
    ipcRenderer.on('update_downloaded', () => {
      ipcRenderer.removeAllListeners('update_downloaded');
      message.innerText = 'Update Downloaded. It will be installed on restart. Restart now?';
      restartButton.classList.remove('hidden');
      notification.classList.remove('hidden');
    });
    function closeNotification() {
      notification.classList.add('hidden');
    }

    function restartApp() {
      ipcRenderer.send('restart_app');
    }
  </script>
</body>

更新
身体{
框大小:边框框;
保证金:0;
填充:20px;
字体系列:无衬线;
背景色:#eaeaea;
文本对齐:居中;
}
#通知{
位置:固定;
底部:20px;
左:20px;
宽度:200px;
填充:20px;
边界半径:5px;
背景色:白色;
盒影:0 4px 8px 0 rgba(0,0,0,0.2);
}
.隐藏{
显示:无;
}
应用程序
版本:

接近 重新启动 const{ipcrender}=require('electron'); const version=document.getElementById('version'); const notification=document.getElementById('notification'); const message=document.getElementById('message'); const restartButton=document.getElementById('restart-button'); 发送('app_version'); ipcRenderer.on('app_version',(事件,参数)=>{ ipcrender.removeAllListeners('app_version'); version.innerText='version'+arg.version; }); ipcRenderer.on('update_available',()=>{ ipcrender.removeAllListeners('update_available'); message.innerText='新的更新可用。正在下载…'; notification.classList.remove('hidden'); }); 在('check_update',()=>{ removeAllListeners('check_update'); message.innerText='正在查找更新…'; notification.classList.remove('hidden'); }); ipcRenderer.on('not_update',()=>{ ipcrender.removeAllListeners('not_update'); message.innerText='更新不可用…'; notification.classList.remove('hidden'); }); ipcRenderer.on('update_downloaded',()=>{ ipcrender.removeAllListeners('update_downloaded'); message.innerText='已下载更新。将在重新启动时安装它。是否立即重新启动?'; restartButton.classList.remove('hidden'); notification.classList.remove('hidden'); }); 函数closeNotification(){ notification.classList.add('hidden'); } 函数restartApp(){ 发送('restart_app'); }
您是否在开发模式下测试了自动更新功能,而不打包应用程序

我也犯了同样的错误,下面的解决方案对我有效

请看一下:

请注意,为了在不打包应用程序的情况下开发/测试更新的UI/UX,您需要一个名为dev-app-update.yml的文件

在本例中,在根目录中创建一个“dev app update.yml”文件,并以yaml格式从package.json中提供发布属性

开发应用程序更新.yml

provider:"github"
owner: "abc"