New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///D:/css/app.css #1769
Comments
Related issue: #1747. |
Try this as an alternative way to get around this path issue: <html>
<head>
<title></title>
</head>
<body>
<script>
var link = document.createElement('link')
link.setAttribute('rel', 'stylesheet')
link.setAttribute('href', require('path').join(__dirname, 'css', 'app.css'))
document.head.appendChild(link)
</script>
</body>
</html> |
@shama Thanks for snippet. |
Have the same issue too. Electron tries to load resources from C:/ , relative paths not working. |
I have the same issue getting some font I have added this to my CSS I have also tried:
but I get this error: |
If this occur when having |
@Myrga you're a life save. I've been looking for an answer for 5 days now, no doc on this, until I came across this old post. Thanks a lot |
ps: if you came here and are using create-react-app, try putting |
thank you so much |
@BesatZardosht You've got a typo in your URL:
should be:
(note the |
In case you are here with the same problem using
publicPath: './', Also if you are building for |
Had same problem, Myrga's solution worked. I think 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 "./" |
Decided to remake my application in React. Once I added file-loader to my project, I started getting this issue again. changing the publicPath property in webpack.config.js to a relative path (for me ./app/ rather than /app/) fixed the problem. P.S. seems that the dev server hates this. If you make this change and want to run a webpack dev server this change will confuse it. You'll need to switch back and forth as you go from working directly in electron and working on dev server (The reason i do this is to do css work, I find the dev server faster and more stable) |
You can save the html file as "save as web page" then try to open in chrome. |
how to solve "Failed to load resource: net::ERR_FILE_NOT_FOUND" |
@Tahawahid @RinatMullayanov Main.js
|
a |
? |
Path issue. Browser search your file in D:/css/app.css. This because somewhere in your code, have mentioned a wrong path. If you are given a path like /css/... this will search in D:/ |
This also did the trick. Thanks for Mr. @itsaakashpatel for the insight. // ...
const { protocol } = require('electron')
// ...
// run the next block right before <BrowserWindow>.loadFile()
const htmlRootDir = 'dist/'
const indexFile = 'index.html'
protocol.interceptFileProtocol(
'file',
(request, callback) => {
const url = request.url.substr(7) // strip "file://" out of all urls
if (request.url.endsWith(indexFile)) {
callback({ path: url })
} else {
callback({ path: path.normalize(`${__dirname}/${htmlRootDir}/${url}`) })
}
},
error => console.error(error)
)
// ... Just replace |
@Myrga Thanks for saving my day. Loved your answer :) |
@Myrga well, you would probably set |
Please @defusioner, is there any doc on this? |
@leodutra humm, I'm using react-cra and they are able to produce such config: https://create-react-app.dev/docs/deployment#building-for-relative-paths |
@defusioner Hum, that explains a lot. In my case, using a Vue.js dist or raw electron, this probably won't work. I think this package approach should be taken in consideration... like some |
I think the But the I spent 8 hours to find out that this is a bug that I can't solve. Then I realized this bug is not important, because the map file is indeed imported. For me, the real bug was caused by |
it works for me |
… build folder Solved by fixing the loading path in electron.js, and by changing the homefolder in package.json according to this issue: electron/electron#1769
Having this same error. Can't load image and other contents from assets folder in Angular 12. When I look in the console I see that it is skipping the project-name-directory and directly looking into the assets folder from the root of my system |
Sorry I'm dumb.
|
If you're using CRA, instead of .env
react-app-rewired webpack: (reactConfig, env) => {
const isDev = env === "development";
if (!isDev) reactConfig.output.publicPath = "./";
return reactConfig;
}, |
This did the trick for me while working with a Vue.js application, thanks! |
I have such a structure in the application:
I write in head my index.html:
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?
The text was updated successfully, but these errors were encountered: