Reputation: 2877
So the structure of my project currently looks like this:
Root
main.js
module.js
...
gui-src
js
script.js
test.js
css
...
...
I want to import module.js
into script.js
(script.js
is part of the renderer process btw). I try to do so using require('../../module')
but I keep getting errors. What's weird is even if I try to load require('./test')
, I get errors from there too! require.main.require()
doesn't give me much luck either...
What exactly is the reason I can't load modules, even ones right next to my source file? Am I misunderstanding require? Or do electron projects work differently than node projects?
Upvotes: 3
Views: 2659
Reputation: 2877
I found out the problem: if you want to include your own module in the renderer process in an electron project, you have to use remote.require(module)
.
Here's more documentation if needed: https://github.com/electron/electron/blob/master/docs/api/remote.md
Upvotes: 2