电子索引.html构建应用程序后不加载

问题描述 投票:0回答:3
我有一个电子应用程序,在将其与

electron-builder

捆绑在一起之前,它可以很好地工作。捆绑并打开应用程序后,我会收到以下错误:

Not allowed to load local resource: file:///tmp/.mount_displa4VwuQh/resources/app.asar/file:/tmp/.mount_displa4VwuQh/resources/app.asar/build/index.html



在“构建文件夹”中,我有

electron.js

文件和
index.html
文件,并且由于应用程序正在启动,因此
electron.js
正确捆绑了。

我是我的
index.html
应用程序入口点(基本上是样板):

electron.js

当尝试使用

const { app, BrowserWindow } = require('electron') const url = require('url') const path = require('path') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let win function createWindow() { // Create the browser window. win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } }) // and load the index.html of the app. win.loadURL(url.format({ pathname: path.join(__dirname, './index.html'), protocol: 'file:', slashes: true })); // Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow) // Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow() } }) // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here.
而不是
loadFile()

时,我会遇到相同的错误,但是使用此路径:

loadUrl()
file:///tmp/.mount_displa4VwuQh/resources/app.asar/index.html
任何想法是怎么了?预先感谢!

因此,看来我的问题毕竟是由于包装不当引起的。将其添加在
javascript electron electron-builder
3个回答
4
投票
“构建”配置中修复了它:

"directories": {
  "buildResources": "build",
  "app": "build"
}

检查您的目录index.html的目录路径
我认为您遵循任何教程,并且不验证您的道路,只需检查一次我希望这可以解决您的问题。

0
投票
./src/index.html

),

您可以分享您的包装。因为我有同样的问题,但还没有找到问题吗?
    


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.