Electron Forge: Preload.js running twice when starting the application

361 Views Asked by At

I am new to electron and working with Electron forge 6 with React as Ui Library with Webpack template. The issue is I want to spawn a process and I am executing the process in preload.js but the preload.js is running twice causing issue in the application.

Please help me how to resolve it.

main.js

  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    // fullscreen: true,
    webPreferences: {
      // nodeIntegration: true,
      // contextIsolation: true,
      // enableRemoteModule: true,
      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
      //attaching the preload script
      // preload: path.join(__dirname, "preload.js"),
    },
  });

  // and load the index.html of the app.
  mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY, { userAgent: "Chrome" });

  // Open the DevTools.
  mainWindow.webContents.openDevTools();
};
0

There are 0 best solutions below