使用Electron-Winstaller找不到模块'./installers/setupEvents'

时间:2018-09-05 21:39:58

标签: javascript angular typescript electron

我正在尝试在Windows 10上打包Angular应用程序,但收到错误消息,并且不确定如何解决该问题:

enter image description here

我正在运行命令:

EditText

转换为电子时所做的更改

index.html 我将"package-win": "electron-packager . qlocktwo-app --overwrite --asar=true --platform=win32 --arch=ia32 --icon=src/assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"QlockTwo App\"", 更改为<base href="/">

electron-main.js

<base href="./">

installers / setupEvents.ts

const setupEvents = require('./installers/setupEvents');
if (setupEvents.handleSquirrelEvent()) {
  return;
}

const {app, BrowserWindow} = require('electron');
let win;

function createWindow () {
  win = new BrowserWindow({width: 800, height: 600});
  win.loadFile('index.html');
  win.webContents.openDevTools();
  win.on('closed', () => {
    win = null;
  })
}

app.on('ready', createWindow);

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

app.on('activate', () => {
  if (win === null) {
    createWindow();
  }
});

installers / windows / createinstaller.js

const electron = require('electron');
const app = electron.app;

module.exports = {
  handleSquirrelEvent: function() {
    if (process.argv.length === 1) {
      return false;
    }

    const ChildProcess = require('child_process');
    const path = require('path');

    const appFolder = path.resolve(process.execPath, '..');
    const rootAtomFolder = path.resolve(appFolder, '..');
    const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
    const exeName = path.basename(process.execPath);
    const spawn = function(command, args) {
      let spawnedProcess, error;

      try {
        spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
      } catch (error) {}

      return spawnedProcess;
    };

    const spawnUpdate = function(args) {
      return spawn(updateDotExe, args);
    };

    const squirrelEvent = process.argv[1];
    switch (squirrelEvent) {
      case '--squirrel-install':
      case '--squirrel-updated':
        spawnUpdate(['--createShortcut', exeName]);

        setTimeout(app.quit, 1000);
        return true;

      case '--squirrel-uninstall':
        spawnUpdate(['--removeShortcut', exeName]);

        setTimeout(app.quit, 1000);
        return true;

      case '--squirrel-obsolete':
        app.quit();
        return true;
    }
  }
};

这是我的文件结构:

enter image description here

2 个答案:

答案 0 :(得分:0)

  1. 删除 node_modules 文件夹
  2. 运行npm cache clean --force
  3. 运行npm install

答案 1 :(得分:0)

尝试安装Electron Winstaller软件包:

npm install --save-dev electronic-winstaller

当然,自清洁电子以来,您需要安装电子。