I'm having an issue where my require('robotjs') or any other third-party libraries are not working. I just get an error saying Unable to laod preload script: my_path_preload.js when using third-party libs. It works fine when I do require('fs') or http
preload.js
const {contextBridge} = require('electron')
const keyboard = require('robotjs')
contextBridge.exposeInMainWorld('api', {
type_something: (something) => {
keyboard.typeString(something);
}
})
index.js
const {context, app, BrowserWindow, contentTracing } = require('electron');
const path = require('path');
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}
const createWindow = () => {
mainWindow = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname,'preload.js')
}
});
mainWindow.loadFile(path.join(__dirname, 'index.html'));
mainWindow.webContents.openDevTools();
};
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
Inside my render.js file I just have a simple function doing window.api.type_something(something)