Cannot find main javascript on remote.require


#1

Hi, I have the following project structure:

Project/
|__main.js
|__app
    |___ 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 ./…/…/.


#2

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.


#3

As I saw in this video: https://www.youtube.com/watch?v=jKzBJAowmGg I want to call a function to switch to another page.


#4

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


#5

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