Electron Builder: Not allowed to load local resource: app.asar/build/index.html

泪湿孤枕 提交于 2020-07-05 06:59:47

问题


I have an issue when using electron builder I got blank page and error in console:

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);

回答1:


Solved by adding "files" in package.json

"files": [
  "*.js",
  "build",
  "node_modules"
],



回答2:


I think your index.html file is not present in your given location. __dirname, '/build/index.html'

I missed this silly point and wasted a lot of time. Angular-cli creates default location for index.html inside a folder in dist.

dist/project-name/index.html



回答3:


I had the same issue and managed to sort it out using:

path.resolve('index.html')

like this:

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




回答4:


I also got the same issue i placed the below line before loading the file.

 window.webContents.openDevTools()

Example Code

// 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()



回答5:


I tried to fix this my whole day & finally found the solution,

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

We need to add files in build section where electron.js is my entry point.



来源:https://stackoverflow.com/questions/45022112/electron-builder-not-allowed-to-load-local-resource-app-asar-build-index-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!