问题
I am writing apps using Electron. The current version, 4.0.6, is based on Node 10.11.0 and Chrome 69.0.3947.106.
I thought the latest version of Electron would support ECMAScript (ES6) modules but I have not been able to make them work, so far. In particular, on starting the app, the line:
import { runTask } from './action';
gives the run-time error:
Uncaught SyntaxError: Unexpected token {
Before I put more effort into tracking down the problems, I would like to know the status of module support in Electron.
Does Electron version 4 (Chrome 69) support ECMAScript (ES6) modules?
回答1:
Chrome has apparently supported them Chrome 63:
https://caniuse.com/#feat=es6-module-dynamic-import
That might mean you can use them in your front-end?
But node v11.11.0 appears to only support them with an extra flag, --experimental-modules
:
https://nodejs.org/api/esm.html
I cannot find a reference, but maybe node 10.11.0 is the same, and that will make them work on the Electron back-end too?
(Sorry, I'm still on an older Electron, and happily using old-fashioned require()
, so cannot tell you from personal experience if it will work.)
回答2:
Surely you are missing the type="module"
attribute on your <script>
tag.
Then you will hit the file protocol issue, which you can work around by registering your own protocol, as described in Electron ES6 module import
来源:https://stackoverflow.com/questions/55044320/does-electron-v4-support-ecmascript-modules