Why .mjs

Alternative 1

As far as I can tell from the latest update, the ability to import ES6 import from CommonJS modules is off the table. The main argument for this was to enable existing modules to upgrade to ES6 without causing any breakage to their CommonJS dependants.

This is a big deal. This means that CommonJS libraries that want to upgrade to ES6 modules will HAVE to bump semver-major version to

View translate-error.js
function translateError(msg) {
var newErr = new Error(msg); // placed here to get correct stack
return e => {
newErr.originalError = e;
throw newErr;
async function asyncTask() {
const user = await UserModel.findById(1).catch(translateError('No user found'))
View mobx-form-prototype.ts
type ValidationError = string | boolean | null;
function fNoError<T>(t:T):ValidationError { return null }
class FieldState<TField> {
private validator: (val:TField) => ValidationError = fNoError
@observable focused = false
@observable changed = false
@observable finisedEditing = false;
View typescript-2.1-json.ts
type Json = null | boolean | string | number | Array<{}> | {}
function tArray<T>(f:(t:any) => t is T) {
return function (a:any): a is Array<T> {
if (!Array.isArray(a)) return false;
for (var k = 0; k < a.length; ++k)
if (!f(a[k])) return false;
return true;
View 01-mobx-async-magic.ts
import {render} from 'react-dom'
import {observable, computed, action} from 'mobx'
import {observer} from 'mobx-react'
import * as React from 'react'
import {fromPromise, IPromiseBasedObservable} from 'mobx-utils'
import 'whatwg-fetch'
import {computedAsync, matchAsync} from './computed-async'
function delay<T>(n:number) {
View promise-variables.js
function getData() {
var respondent = Respondent.findById(respondentId)
var box = respondent.then(r => Box.findById(r.box_id))
var user = box.then(box => User.findById(box.owned_by))
return Promise.props({user, box, respondent})

Async-sync correspondence

Just like typical expressions are evaluated at time of assignment, promise expressions are also evaluated eagerly.

Promise values act like regular values. You can reuse regular variable values later:

var x = someExpression()

// some other method or function, later:
View deferred-promise-use-case.js
// These theoretical API requests are deferred promises;
// Not executed until `.then()` is invoked.
let a = new Request('/foo');
let b = new Request('/bar');
let c = new Request('/baz');
// If invoked directly, then issue 3 direct HTTP requests:
Promise.all([ a, b, b ]).then((results) => {
// GET /foo
// GET /bar
View build.yaml
info: >
build_all: >
npm-run-all build_es6 build_amd build_cjs build_global generate_packages
build_amd: >
npm-run-all clean_dist_amd copy_src_amd compile_dist_amd
build_cjs: >
View gist:326dc27aa6fca07f4f23b13e89df637e
"type": "ArrowFunctionExpression",
"id": null,
"params": [
"type": "Identifier",
"name": "n"
"defaults": [],