Cannot find main javascript on remote.require


Hi, I have the following project structure:

    |___ js
         |__ login.js

In login.js I need to import main.js:

const remote = require(‘electron’).remote
const main = remote.require(’…/…/main.js’)

The problem is that the above piece of code doesn’t work. I tried multiple ways without path, with ./…/…/.


What is the reason for wanting to do this?

First off, it’s important to understand exactly what remote.require(), does. As per the docs:

Returns the object returned by require(module) in the main process.

What do you think you need to be requireing main.js? That’s typically for the main process, something that doesn’t make much sense to be the target of a require, much less via the remote which targets the main process as the processing component.


As I saw in this video: I want to call a function to switch to another page.


Ah, ok. Makes sense. What’s the specific error message you’re getting? Is your code posted somewhere?


You could probably use IPC for that. The renderer process (your login script) may send a signal that the main process (your main.js) receives. There is a lot of info on IPC if you search this and other forums