14

我在使用电子生成器时遇到问题,我在控制台中出现空白页和错误:

Not allowed to load local resource: file:///C:/Users/emretekince/Desktop/DCSLogBook/client/dist/win-unpacked/resources/app.asar/build/index.html

main.js

const startUrl = process.env.ELECTRON_START_URL || url.format({
        pathname: path.join(__dirname, '/build/index.html'),
        protocol: 'file:',
        slashes: true
    });
mainWindow.loadURL(startUrl);
4

6 回答 6

9

通过在 package.json 中添加“文件”解决

"files": [
  "*.js",
  "build",
  "node_modules"
],
于 2017-07-11T11:03:08.013 回答
5

我认为您的 index.html 文件不存在于您的给定位置。__dirname, '/build/index.html'

我错过了这个愚蠢的点,浪费了很多时间。Angular-cli 在 dist 的文件夹中创建 index.html 的默认位置。

dist/project-name/index.html
于 2018-11-01T20:07:03.767 回答
2

我遇到了同样的问题,并设法使用以下方法对其进行了整理:

path.resolve('index.html')

像这样:

const startUrl = path.resolve('index.html'); mainWindow.loadURL(startUrl);

于 2018-06-27T11:44:27.117 回答
1

我一整天都试图解决这个问题,终于找到了解决方案,

"build": {
"appId": "myledgerapp",
"extends": null,
"files": [
  "./build/**/*",
  "./public/electron.js"
]}

我们需要在 electron.js 是我的入口点的构建部分添加文件。

于 2019-04-21T11:18:07.887 回答
0

我也遇到了同样的问题,我在加载文件之前放置了下面的行。

 window.webContents.openDevTools()

示例代码

// Issue code
window =  new BrowserWindow({width:800,height:600,parent:mainWindow})
window.webContents.openDevTools()
window.loadURL(url.format({
    pathname: path.join(__dirname,'/../views/file.html'),
    protocol: 'file',
    slashes: true
}))

// Issue Solved code
window =  new BrowserWindow({width:800,height:600,parent:mainWindow})

window.loadURL(url.format({
    pathname: path.join(__dirname,'/../views/file.html'),
    protocol: 'file',
    slashes: true
}))
window.webContents.openDevTools()
于 2018-07-15T15:29:20.827 回答
0

我遇到了类似的问题并且缺少path.join

错误代码:

win.loadFile('index.html')

固定代码:

win.loadFile(path.join(__dirname, 'index.html'))
于 2021-08-29T19:35:30.233 回答