admin管理员组文章数量:1313991
I'm building my electron app, specifically trying out ipc process for customizable minimize, maximize, close buttons, and ran into this error:
Unable to load preload script: C:\Users\username\generic_project\generic_project_ver_alpha.webpack\main\preload.ts
I looked at .webpack/main and it is true, there's no preload.js there. I followed the two webpages below in my initial setup:
Here's my code:
index.ts
const createWindow = (): void => {
const mainWindow = new BrowserWindow({
height: 1280,
width: 844,
frame: false,
webPreferences: {
preload: path.join(__dirname, "preload.ts"), // Ensure correct path
nodeIntegration: true, //security risk?
contextIsolation: true, //for context bridge api
sandbox: false
},
});
// and load the index.html of the app.
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
// Open the DevTools.
mainWindow.webContents.openDevTools();
};
preload.ts
import { ipcRenderer, contextBridge } from "electron";
contextBridge.exposeInMainWorld("electron", {
send: (channel: string, data: any) => ipcRenderer.send(channel, data),
receive: (channel: string, func: (event: any, ...args: any[]) => void) =>
ipcRenderer.on(channel, (event, ...args) => func(event, ...args)),
});
fe.config.ts plugins:
plugins: [
new AutoUnpackNativesPlugin({}),
new WebpackPlugin({
mainConfig,
renderer: {
config: rendererConfig,
entryPoints: [
{
html: './src/index.html',
js: './src/renderer.ts',
name: 'main_window',
preload: {
js: './src/preload.ts',
},
},
],
},
}),
My path:
- src/
- components/
- SideBar.tsx
- TopBar.tsx
- App.tsx
- index.tsx
- index.css
- index.html
- preload.ts
- renderer.ts
- components/
I've looked up the answers online and try out solutions like enabling nodeIntegration, setting sandbox to false but nothing seems to work.
If anyone can point me to the nature of the problem, it would be very helpful. Thanks.
本文标签: reactjsUnable to load preload scriptStack Overflow
版权声明:本文标题:reactjs - Unable to load preload script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741929376a2405483.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论