I am trying to learn ElectronJS. I am OK with "Vanilla" JavaScript but when it comes to Node I am clueless. Everything works when I use the tag in my html and run all the code from that .js code. However I am now trying to import a class and get an ERR_FILE_NOT_FOUND error when I launch the program. This is the basic code explaining where my problem happens.
Vector3 Class:
export class Vector3{
constructor(x, y, z){
this.x = x;
this.y = y;
this.z = z;
}
}
Test.js file used in <script type="module" src="Test.js>
import {Vector3} from "./mathf/Vector3"
function main(){
let vec = new Vector3(1.0, 1.0, 1.0);
console.log(vec.x);
}
window.onload = main;
I even had a look at RequireJS but I seemed to get more errors (due to me not knowing what is going on)
I also tried the const {Vector3} = require('./mathf/Vector3'); And used module.exports.Vector3 = Vector3 in my Vector3.js file. But require is not defined seeing as it's running the JS on the client side.
Can anyone please point me in the right direction or tell me how I would be able to import the Vector3 class into my test.js code?
.
+-- mathf
| +-- Vector3.js
+-- node_modules
| +-- ...
+-- main.html
+-- main.js
+-- package-lock.json
+-- package.json
+-- Test.js
<=========== SOLUTION ===========>
The solution was to simply add the following when creating the BrowserWindow()
mainWindow = new BrowserWindow({
webPreferences:{
contextIsolation: false,
nodeIntegration: true,
nodeIntegrationInWorker: true
}
});