Now that Electron has hit Chrome's 60s we can have proper module support. But of course, the standard (for very good reasons) prevents loading modules from file:
and it makes sense for both Electron and NW.js to adhere to the statusquo.
So if you were really excited and this bums you, don't worry, you are in for awesome things.
The future Electron eco-system offers two options for native ES modules:
-
Custom Electron protocol via Chromium's module loading subsystem
-
Custom NodeJS loaders via Node's module loading subsystem recommended
Both methods can coexist. In fact, so far from tests, it seems that at least for hybrid applications, using both methods together will be the more suitable path.
This focuses on the first.
Revision: Draft 2
I am trying to figure out the best way to write a new electron app in 2023 using only ES modules. Is this still a good approach? Or are there better ways now? I do not want to use a local server to deliver esm.
Do you know if its possible at this time to enable the file: protocol to work in the renderer? I am a bit confused about why enabling nodeIntegration does not also allow the ESM loader to load from file:
BTW, my goal is to disable network fetch by default and treat security from a local perspective. If my electron app does not allow loading remote URLs, I am thinking that is would be better to allow the file: protocol to work from the renderer so that I dont have to use a custom protocol schema in my imports.