17

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
  • Any restricting options when initializing the BrowserWindow? Commented Jul 11, 2017 at 4:30

6 Answers 6

10

Solved by adding "files" in package.json

"files": [
  "*.js",
  "build",
  "node_modules"
],
Sign up to request clarification or add additional context in comments.

4 Comments

This is not worked for me. what the files actually do?
How do you know what to add to "files"?
Where should I add the Files? I have added it to my package.json.But no change, the error persists
I used this as well as moving my html file into the static folder. So I just added "static" to the list inside of "files".
6

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.

2 Comments

@Akashxoloti, but what does 'files' do if included?
@Vass I think It may including above mentioned files into app.asar. which is placed inside dist/resources
5

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

Comments

4

I got a similar problem and was missing the path.join:

Bad Code:

win.loadFile('index.html')

Fixed Code:

win.loadFile(path.join(__dirname, 'index.html'))

Comments

2

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.