Description
Important
Support for ES Modules in Electron will land in Electron 28 and will be available in the electron-nightly
released on August 31st
🥳
Original Issue Below
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Feature Request
As of Node 13.3 ES modules have been unflagged (albeit still experimental), it would be nice to be able to use ES modules as supported in electron.
Currently when trying to run electron with an ES entry point (either .mjs
or .js
+"type": "module"
) electron fails to run.
For example:
> [email protected] start /home/jamesernator/Projects/electron-test
> electron .
App threw an error during load
/home/jamesernator/Projects/electron-test/main.js:1
import electron from 'electron';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:815:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:892:10)
at Module.load (internal/modules/cjs/loader.js:735:32)
at Module._load (internal/modules/cjs/loader.js:648:12)
at Module._load (electron/js2c/asar.js:717:26)
at Function.Module._load (electron/js2c/asar.js:717:26)
at loadApplicationPackage (/home/jamesernator/Projects/electron-test/node_modules/electron/dist/resources/default_app.asar/main.js:109:16)
at Object.<anonymous> (/home/jamesernator/Projects/electron-test/node_modules/electron/dist/resources/default_app.asar/main.js:155:9)
at Module._compile (internal/modules/cjs/loader.js:880:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:892:10)
Alternatives Considered
This is primarily a request for support, the alternative is not supporting it but that would be unfortunate given ES modules will be officially supported in both browsers and Node but not usable by electron without additional tooling.
Additional Information
ES Modules are still new (and experimental) so actual implementation might be delayed (or put behind flag) however starting to consider implementation considerations now would be helpful for supporting this more readily in future.