Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use *.es.js instead of *.mjs for ES builds? #3057

Closed
fskreuz opened this issue Aug 15, 2017 · 2 comments
Closed

Use *.es.js instead of *.mjs for ES builds? #3057

fskreuz opened this issue Aug 15, 2017 · 2 comments

Comments

@fskreuz
Copy link
Contributor

fskreuz commented Aug 15, 2017

Description:

Unlike regular scripts, modules scripts must be served with one of the valid JavaScript MIME types else they won't execute.
https://jakearchibald.com/2017/es-modules-in-browsers/#mime-types

Some (most?) servers don't know what .mjs is which causes servers to serve the wrong mime type (octet stream?) which causes browsers to not execute the module.

I think in Node, they're moving towards pkg.module (from .mjs and pkg.jsnext:main) which means .mjs won't be getting a good mimetype anytime soon. And server-side configuration is annoying, especially if you don't have access/can't configure/don't know how to do it/just can't do it.

Also, the regular build could be *.umd.js for consistency.

I could be wrong. Thoughts?

Versions affected:

All builds that emit .mjs.

Platforms affected:

Chrome (60? The one that supports ES modules). Have not tested Safari (I'm rarely on a Mac when playing around).

Reproduction:

  1. Install the Chrome version that supports ES modules.
  2. Install lite-server (I think http-server also works just as fine).
  3. Create two JS modules, one importing the other. You can just add a console.log() on both.
  4. Create an HTML with <script type="module" src="path/to/script/that/loads/the/other.js">.
  5. Run the static server to serve that HTML.

Browser loads both scripts, but won't parse the second one (and possibly its dependencies), causing the entire tree to just halt. Chrome silently fails when this happens, not even a parse error.

@fskreuz fskreuz changed the title Use *.es.js instead of .mjs for ES builds? Use *.es.js instead of *.mjs for ES builds? Aug 15, 2017
@fskreuz fskreuz added this to the 1.0.0 milestone Aug 15, 2017
@evs-chris
Copy link
Contributor

I think it wouldn't hurt to throw out a ractive.es.js that is also not transpiled and leave the .mjs as transpiled. This all gets a bit confusing with node starting to use .mjs and various bundlers using the pkg:module or pkg:jsnext:main. You can legitimately want a transpiled es module for use with IE via webpack, but want to use modules in browser where transpilation only adds fluff to the code.

Is anyone clear on exactly what/when/why node will load an mjs over a js? Once that's settled, we can decide whether to point the pkg:module at the transpiled version that is appropriate.

@fskreuz fskreuz modified the milestones: 1.0.0, unknown/unspecified Oct 9, 2017
@fskreuz
Copy link
Contributor Author

fskreuz commented Oct 9, 2017

Haven't been in the JS scene for a while, not sure where it's headed. But I read Node is really going for .mjs. I think it won't be long before servers and tooling serve .mjs as JavaScript in line with Node using .mjs for ES modules. This was just a stopgap solution to have existing servers use the correct mimetype without fiddling with the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants