PNG files not found in ASAR

谁都会走 提交于 2019-12-24 01:33:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!