Stencil Electron net::ERR_FILE_NOT_FOUND

I built a Stencil app and when it was all done, I added Capacitor Electron to it. When I run the app:

stencil build
npx cap sync
npx cap open electron

The Electron container opens and the base index.html file loads, but as soon as it tries to load the first bundled .js file, I get the following error:

GET file:///D:/build/p-267af940.js net::ERR_FILE_NOT_FOUND

I read a bunch of the related posts here and on stack overflow and haven’t found a solution that works for me. For example, I tried changing the <base href="./"> as mentioned in many of the articles, to no avail.

I’m fairly certain this is a content security policy issue, but I can’t find any guidelines anywhere about how to set it up correctly and this recent post is still unanswered: Looking for comprehensive content-security-policy guideline.

When I first launched the app, I got a security policy error which I searched for and found a recommendation to set it like this:

<meta http-equiv="Content-Security-Policy" content="script-src 'self';">

That fixed that issue, but now I can’t load any local files. I’ll start playing around with policy settings, but what’s the recommendation for Stencil, Capacitor, and Electron?

Can someone please help? I created a new stencil project from scratch this morning, then added Capacitor and Electron and got the same error. I know Electron support is in beta, but has anybody been able to get this working?

My app connects to an ESP32 microcontroller and consumes an API there over TLS. Because of my self-signed certificate, I can’t do any of this in the browser, so I need another approach - like Electron.

Similar to what was said here

This is due to file protocol loading and single page apps. It’s the same reason we have a web server in ios and android.

Electron-server looks like it will handle what you need.

This approach is also run by default in the next Capacitor/electron iteration. Its still in testing phases but so far of all the web-app types (stencil, angular, react, vue, ect.) I haven’t found one where their getting started example would not run as expected with this approach.