electron: ES6 modules don't work in 2.0.0-beta.1
- Electron version: 2.0.0-beta.1
- Operating system: macOS 10.13.3
<script src="script.js" type="module"></script> should execute the code in script.js file. Instead, the following error is thrown:
Failed to load module script: The server responded with a non-JavaScript MIME type of “”. Strict MIME type checking is enforced for module scripts per HTML spec.
NW.js used to be affected by exactly the same issue: https://github.com/nwjs/nw.js/issues/6106
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 27 (4 by maintainers)
Commits related to this issue
- ts target: es5 - https://github.com/electron/electron/issues/12011 — committed to frederiksen/angular-electron-boilerplate by deleted user 5 years ago
Could this protocol thing be somehow abstracted away by Electron? Most developers (including me) don’t even know what custom protocols are and I would expect a core language feature such as modules to work out of the box.
@jarrodek If Chromium needs a server to serve ES modules, instead of the direct filesystem, then Electron should be a server (as far as Chromium is concerned).
Loading es6 modules over null origin (file:// scheme) is not supported by standard https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script, we would like to follow similar behavior. At the moment we are setting CORS header for
file://to support service workers in electron, but this will be removed in the upcoming version. Closing this as expected behavior. Thanks!I agree with what @Lonniebiz says. There are so many unresolved issues related to this (service worker, es6 modules, security), that it would make things just much easier. It wouldn’t even need to be the default behavior. Providing a standard convenient way for new projects to do so, would be enough.