问题
I have an Electron (1.7.10) application that is reporting it can't find 5 of 7 PNG files in my ASAR. All 7 PNGs are in the same folder, and 2 of them are displayed on screen fine. The other 5 report net::ERR_FILE_NOT_FOUND.
All src attributes for the img tags are dynamically generated and use relative paths (assets/images/MyImage.png
). If I extract the ASAR, I can see the files in there, in the correct folder (as referenced by the src attribute).
If I use the console to set the location of my browser to one of the images (document.location.href = "file:///path/to/app.asar/dist/assets/images/MyImage.png"
) I get the same results - 2 of 7 show OK.
Before packaging my application (with electron-builder), all images show correctly.
Any ideas?
Thanks,
TTE
回答1:
const path = require('path');
path.join(__dirname, 'assets/images/MyImage.png');
回答2:
Let me guess, you are building a react SPA using react-router, and BrowserRouter?
If so, use HashRouter instead. Electron does not work with SPA's route by default, because a SPA route changes, but the resource path is always relative to index.html.
来源:https://stackoverflow.com/questions/49614896/png-files-not-found-in-asar