This post contains content about Now 1.0 – Learn about the latest version, Now 2.0.
Now 2.0 - Upgrade Available
ES Modules are starting to see wide support by mainstream browsers and platforms. This means having the ability to use the import and export keywords across all your codebases, in many cases without even needing a transpilation step.
I’m happy to announce that effective immediately, you can develop server and browser JavaScript applications on Now that use this new module system. Read on to learn how.
The Node.js project has recently merged in support for ES modules. For backwards compatibility reasons, since Node.js already had its own module system with different script evaluation semantics, ES module support in Node.js requires the usage of the .mjs extension.
Starting with Node.js 8.5.0, you can test out ES Modules by using the --experimental-modules flag. Since Now supports the 8.x branch, we put together an example on how to create a microservice using micro and ESM on Now. You can clone it from GitHub and query it live!
On the browser side of things, the only requirement is that you use <script type="module"> to load your scripts. The file can end in .js or .mjs. However, a lot of web servers and hosting solutions have never heard of mjs, so they use the wrong Content-Type when serving your files. The specification mandates that, unlike regular scripts, module scripts must be served with a valid JS Content-Type.
Starting today, Now static hosting correctly handles .mjs by sending the right Content-Type! We put together for you to see it in action:
When you develop static websites locally, you’ll find that accessing your files directly over the file:// protocol is quite problematic. On both Chrome and Firefox the example above won’t run.
To make local development easier and more production-like, we developed the serve tool, which sets up a HTTP server on localhost that simply serves your files. Starting with the newly released serve 6.2.0, the .mjs Content-Type is correctly handled. Run npm install -g serve to get the latest, and then run the serve command inside any directory.
We’ve made this deployment open source, which means you can view its source code directly in Now by appending /_src at the end of the URL. To give you the best experience, we’ve also upgraded our web viewer to recognize mjs:
Chrome has shipped support for modules with their stable release 61 and Safari on 10.1. For Firefox Nightly users, I recommend turning on the dom.moduleScripts.enabled to start experimenting with this feature, as shown below.

The flag you need to turn on for Firefox ESM support

Edge has similarly enabled them behind "experimental JavaScript features" found in about:flags.
To learn more about the details and nuances of ECMAScript modules, we recommend this great reference article by Jake Archibald from the Chrome team.
We are excited about the possibilities a unified module system brings to the JavaScript platform. We are working to take advantage of the new native support in many of our core OSS projects. Chat with us to find out more!