electron: Failed to load resource: net::ERR_FILE_NOT_FOUND file:///D:/css/app.css
I have such a structure in the application:
I write in head my index.html:
<link rel="stylesheet" href="css/app.css"/>
run electron and get error:
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///D:/css/app.css
Please everyone, tell me, how should I set the path to the file?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 31 (2 by maintainers)
If this occur when having
<base href="/">in the index.html, just replace it by<base href="./">.ps: if you came here and are using create-react-app, try putting
"homepage": "./",in your package.json. (Although apparently this is not currently supported so you might have other issues with fonts and such, which might require moving those assets to your /public folder)Related issue: #1747.
You can save the html file as “save as web page” then try to open in chrome. This worked for me.
@shama Thanks for snippet. I get an error because the use <base href=“/”>, without this error does not occur. Sample work https://github.com/RinatMullayanov/angular-boilerplate branch electron.
a
In case you are here with the same problem using
Webpack 2.x,Reactand/orRedux, there is a chance that this would solve your problem:Also if you are building for
Electronyou may need to add/modify the Webpacktargetproperty. Stay Happy!! 😄@Tahawahid @RinatMullayanov It’s because of your all files are being served from the local file system rather than the relative app path. The solution is to intercept the file protocol. Do following changes in main.js file
Main.js
mainWindow = new BrowserWindow({width: 1100, height: 700, icon: __dirname + '/icon.ico'}) mainWindow.loadURL(url.format({ pathname:'index.html', protocol: 'file', slashes: true }))app.on('ready', () => { protocol.interceptFileProtocol('file', (request, callback) => { const url = request.url.substr(7) /* all urls start with 'file://' */ callback({ path: path.normalize(${__dirname}/${url})}) }, (err) => { if (err) console.error('Failed to register protocol') }) createWindow() /* callback function */ })Try this as an alternative way to get around this path issue:
@Myrga well, you would probably set
"homepage": "./"in thepackage.jsoninstead of hard-coding these things.This also did the trick. Thanks for Mr. @itsaakashpatel for the insight.
Just replace
htmlRootDirand/orindexFilefor your expectations. Tested on LinuxHad same problem, Myrga’s solution worked. I think <base href="/"> must consider / as global root directory for the PC when using file protocol. While “./” works as a relative reference to the current folder. Just a guess, when using http:// protocol on port 4200 (Where I serve my Angular4 app) everything works with “/”. For file protocol have to use “./”
I have the same issue getting some font
I have added this to my CSS
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);I have even tried adding this to my html:<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />I have also tried:
<link rel="stylesheet" type="text/css" href="http//fonts.googleapis.com/css?family=Open+Sans" /><link rel="stylesheet" type="text/css" href="https//fonts.googleapis.com/css?family=Open+Sans" />but I get this error:
Failed to load resource: net::ERR_CONNECTION_REFUSED