0

I have already searched in the others posts of stackflow with the same error, but aparently my problem is not about nodeIntegration parameter. Because, even the paramater of nodeIntegration is set true, i still get the undefined problem of require in the main-login.js file! PS: All files is in the same root and directory...

main.js

const { app, BrowserWindow, remote, ipcMain } = require("electron");
const path = require("path");

//Funcionalidade de criar window
function createWindow() {
  const win = new BrowserWindow({
    webPreferences: {
      nodeIntegration: true,
      preload: path.join(__dirname, "preload.js")
    },
  });

  win.maximize();

  win.loadFile("index.html");
}

//Chamada da funcionalidade de criação do window
app.whenReady().then(() => {
  createWindow();

  app.on("activate", function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

//Fechamento do app quando todos os windows forem fechados
app.on("window-all-closed", function () {
  if (process.platform !== "darwin") app.quit();
});

//Aprovação da validação do login
ipcMain.on("validation", function (e, item) {
  console.log(item);
})

index.html

<!DOCTYPE html>
<html lang="en">
<head>...</head>
<body>

    <div class="container-login100" style="background-image: url('images/pdv-login.jpg');">

        ...

                <div class="container-login100-form-btn">
                    <button class="login100-form-btn">
                        Entrar
                    </button>
                </div>
        </div>
    </div>
    

<!--===============================================================================================-->
    <script src="vendor/jquery/jquery-3.2.1.min.js"></script>
...
    <script src="vendor/countdowntime/countdowntime.js"></script>
<!--===============================================================================================-->
    <script src="main-login.js"></script>

</body>
</html>

main-login.js

const { ipcRenderer } = require('electron');

(function ($) {
  "use strict";


  ...

  function hideValidate(input) {
    var thisAlert = $(input).parent();
    $(thisAlert).removeClass("alert-validate");
    $(thisAlert).find(".btn-hide-validate").remove();
  }
})(jQuery);
  • Does this answer your question? [Electron require() is not defined](https://stackoverflow.com/questions/44391448/electron-require-is-not-defined) – snwflk Jun 06 '21 at 13:20
  • You can use `contextIsolation: false` to circumvent this problem. Make sure to read up on [contextIsolation](https://github.com/electron/electron/blob/main/docs/tutorial/context-isolation.md) to decide if it's a good idea or not. – snwflk Jun 06 '21 at 13:22
  • Yes! I have actually solved this problem, by using that. But, is there any solution to use require in other process which isn the main process? – Hsu Chu Julio Jun 08 '21 at 09:05

0 Answers0