We have an electron app and want to load the renderer bundle using loadUrl()
.
win=new BrowserWindow({ /* ... */ })
win.loadURL(`file://${path.join(__dirname, '../../render/build/index.html')}`);
Inside the html file, we load the React Bundle
<script type="text/javascript" src="/js/app-my-hash.bundle.js"></script>
However, as expected, the file is not found, since, I guess, I need to set the root of the project somehow. I get this error
Failed to load resource: net::ERR_FILE_NOT_FOUND
What setting am I missing on the electron side (or webpack side) to get this working?
We have an electron app and want to load the renderer bundle using loadUrl()
.
win=new BrowserWindow({ /* ... */ })
win.loadURL(`file://${path.join(__dirname, '../../render/build/index.html')}`);
Inside the html file, we load the React Bundle
<script type="text/javascript" src="/js/app-my-hash.bundle.js"></script>
However, as expected, the file is not found, since, I guess, I need to set the root of the project somehow. I get this error
Failed to load resource: net::ERR_FILE_NOT_FOUND
What setting am I missing on the electron side (or webpack side) to get this working?
Share Improve this question asked Apr 10, 2019 at 18:15 Andrei CioaraAndrei Cioara 3,6747 gold badges41 silver badges64 bronze badges 5- Which file is not found? If index.html, does it load if you use absolute address instead of path.join? Or app-my-hash.bundle.js ? If yes, Is it in root js folder? Did you try to load it with require('myfile.js')? – Nemi Commented Apr 10, 2019 at 18:36
- The JS is missing. It is not in root js. It is in a js folder that is relative to the index.html. I did not try to load it with require, it is bundled by webpack. – Andrei Cioara Commented Apr 10, 2019 at 18:50
-
3
Try relative URL, like:
src="js/app-my-hash.bundle.js"
orsrc="./js/app-my-hash.bundle.js"
– Nemi Commented Apr 10, 2019 at 18:58 - Yup. That worked. – Andrei Cioara Commented Apr 10, 2019 at 21:02
- Great. I put it as answer. – Nemi Commented Apr 10, 2019 at 22:48
2 Answers
Reset to default 4Another approach to add relative path without manual update in index.html is by including,
homepage property in package.json.
For an example,
{
"name": "electron-project",
"homepage": "./", # Add this line
#.... all remaining properties
}
Stackoverflow Source
Use relative URL, like: src="js/app-my-hash.bundle.js"
or src="./js/app-my-hash.bundle.js"