electron-builder: Resources from static/media are not resolvable after package
- Version: 21.2.0
- Target: Linux deb
I am using CRA to build the app and getting such build structure:

After building the project with electron, the application does not substitute the correct path to the files from static/media and does not find them.
./static/media/logo.4c2ab132.svg -> file:///static/media/logo.4c2ab132.svg.
Although the paths for the files in static/css and static/js are defined correctly (full path to app.asar).
./static/media/logo.4c2ab132.svg -> file:///home/user/path/to/app.asar/build/static/css/main.a20d4a01.chunk.css.
In the final index.html all this file paths are relative.
What is the problem?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19
I also had this problem, the files in ‘build/static/media/*.png’ (and gifs too). They were not found. solution: note: I’m using react and building with electron https://stackoverflow.com/questions/45178195/image-assets-not-found-in-packaged-electron-app-angular4-and-webpack Only add
<base href="./">in ‘public/index.html’I just manually placed the files in a public folder and after packaging they are still unavailable, which means the problem is not related to the webpack or CRA. Although all these files are present in app.asar and if you manually set the correct path, the file will be available.
Maybe
FileSet.from/FileSet.toor manipulating withfilesandbuildResourcesinpackage.jsonis close to the right solution but I didn’t succeed with it.I found electron-serve for serving static files in electron. But I did not understand how it works because I did not have time to use it.
But I found a solution for myself. I used protocol.interceptFileProtocol() for modifying paths to requested resources. Example of usage on stackoverflow
@srepollock, I think it’s suitable for you too. Here is needed part of my code in
main.js:I feel it more like workaround, but seems it’s appropriate solution in context of electron applications.
man u r a hero .thanks alot