Building an electron app and got stuck with an error. I don't understand why my preload.js doesn't find the 'dnode' nor the 'path' modules, but it does find the 'url' module.
preload.js:
const { ipcRenderer } = require('electron');
const url = require('url');
const dnode = require('dnode'); // It breaks here with 'Error: module not found: dnode'
process.once('loaded', () => {
window.addEventListener('message', event => {
const message = event.data;
if (message.myTypeField === 'handler') {
// TO-DO
}
});
});
main.js
const url = require('url');
const path = require('path');
const {app, ipcMain, BrowserWindow} = require('electron');
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
backgroundColor: '#fff',
webPreferences: {
preload: path.join(__dirname, './preload.js'),
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
sandbox: true
}
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol:'file:',
slashes: true
}));
});
My main.js finds the 'path' and 'dnode' modules tho, I've tried changing preload.js to the root directory of the project next to the node_modules folder and It didn't work.