2021年3月21日星期日

Electron App : Unable to load preload script

Been getting this error every time I start up my electron app.

electron/js2c/renderer_init.js:91 Unable to load preload script: C:\Users\Desktop\Projects\Electron-Apps\Electron\src\preload.js  (anonymous) @ electron/js2c/renderer_init.js:91  electron/js2c/renderer_init.js:91 Error: contextBridge API can only be used when contextIsolation is enabled  

My preload.js is in the same directory as my index.js, so I'm a bit loss at debugging this. Not sure why it won't load my preload.js file. Everything was working fine up until I setup my default formatter to prettier with eslint.

Index.js

const createWindow = () => {    // Create the browser window.    const mainWindow = new BrowserWindow({      width: 800,      height: 600,      webPreferences: {        preload: path.join(__dirname, 'preload.js'),      },    });  

Preload.js

const { contextBridge, ipcRenderer } = require('electron');    contextBridge.exposeInMainWorld('electron', {    notificationAPI: {      sendNotification(message) {        ipcRenderer.send('notify', message);      },    },    filesAPI: {      sendEmails(content) {        ipcRenderer.send('save-delete', content);      },    },  });  
https://stackoverflow.com/questions/66739463/electron-app-unable-to-load-preload-script March 22, 2021 at 10:04AM

没有评论:

发表评论