My project's build directory structure:
build
???preload
? ??? preload.js (electron preload)
?
???index.js (electron entry point)
???index.html (react html)
???renderer.js (react entry point)
?
???resources
??? models (tensorflow models)
? ??? model.json
? ??? sub1.bin
? ??? sub2.bin
?
??? icons
??? icon.icns
??? icon.ico
I'm trying to load the tensorflow model to my preload scripts:
//preload.js
await tf.loadLayersModel(path.resolve(__dirname, "../resources/models/model.json"));
Then this error is thrown and shown in the renderer (the Electron window).->
build/resources/model/model.json failed with status code 404. Please verify this URL points to the model JSON of the model to load.:undefined:undefined
And this error in the developer tools->
Get http://localhost:3000/{MyProjectDir}/build/resources/models/model.json failed with status code 404.
In my opinion, because Electron runs the preload script in the renderer, __dirname becomes the localhost server, and it tries to find the model.json from the url, but I think the problem occurs because there is no router that handles this. Am I right?
But I still don't know how to solve it. How can I load model.json and bin files in the preload.js that is built?
I double-check my code's importing path, but i think there is no problem there.