esm
Tomorrow's ECMAScript modules today!
Last updated 7 months ago by jdalton .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install esm 
SYNC missed versions from official npm registry.

esm

The brilliantly simple, babel-less, bundle-less ECMAScript module loader.

esm is the world’s most advanced ECMAScript module loader. This fast, production ready, zero dependency loader is all you need to support ECMAScript modules in Node 6+. See the release post and video for details!

Install

  • New projects

    Run npm init esm or yarn create esm.

    :bulb: Use the -y flag to answer “yes” to all prompts.

  • Existing projects

    Run npm i esm or yarn add esm.

Getting started

There are two ways to enable esm.

  1. Enable esm for packages:

    Use esm to load the main ES module and export it as CommonJS.

    index.js

    // Set options as a parameter, environment variable, or rc file.
    require = require("esm")(module/*, options*/)
    module.exports = require("./main.js")
    

    main.js

    // ESM syntax is supported.
    export {}
    

    :bulb: These files are automagically created with npm init esm or yarn create esm.

  2. Enable esm for local runs:

    node -r esm main.js
    

    :bulb: Omit the filename to enable esm in the REPL.

Features

:clap: By default, :100: percent CJS interoperability is enabled so you can get stuff done.
:lock: .mjs files are limited to basic functionality without support for esm options.

Out of the box esm just works, no configuration necessary, and supports:

Options

Specify options with one of the following:

  • "esm" field in package.json
  • CJS/ESM in an .esmrc.js, .esmrc.cjs, or .esmrc.mjs file
  • JSON6 in an .esmrc or .esmrc.json file
  • JSON6 or file path in the ESM_OPTIONS environment variable
  • ESM_DISABLE_CACHE environment variable
{
"cjs":true

A boolean or object for toggling CJS features in ESM.

<summary>Features</summary>
{
"cache":true

A boolean for storing ES modules in require.cache.

"esModule":true

A boolean for __esModule interoperability.

"extensions":true

A boolean for respecting require.extensions in ESM.

"mutableNamespace":true

A boolean for mutable namespace objects.

"namedExports":true

A boolean for importing named exports of CJS modules.

"paths":true

A boolean for following CJS path rules in ESM.

"vars":true

A boolean for __dirname, __filename, and require in ESM.

"dedefault":false

A boolean for requiring ES modules without the dangling require().default.

"topLevelReturn":false

A boolean for top-level return support.

}
"mainFields":["main"]

An array of fields checked when importing a package.

"mode":"auto"

A string mode:

  • "auto" detect files with import, import.meta, export,
    "use module", or .mjs as ESM.
  • "all" files besides those with "use script" or .cjs are treated as ESM.
  • "strict" to treat only .mjs files as ESM.
"await":false

A boolean for top-level await in modules without ESM exports. (Node 10+)

"force":false

A boolean to apply these options to all module loads.

"wasm":false

A boolean for WebAssembly module support. (Node 8+)

}

DevOpts

{
"cache":true

A boolean for toggling cache creation or a cache directory path.

"sourceMap":false

A boolean for including inline source maps.

}

Tips

Bundling

  • For bundlers like browserify+esmify, parcel-bundler, and webpack add a "module" field to package.json pointing to the main ES module.

    "main": "index.js",
    "module": "main.js"
    

    :bulb: This is automagically done with npm init esm or yarn create esm.

Extensions

Loading

  • Load esm before loaders/monitors like @babel/register, newrelic, sqreen, and ts-node.

  • Load esm for jasmine using the "helpers" field in jasmine.json:

    "helpers": [
      "node_modules/esm"
    ]
    
  • Load esm with “node-args" options of:

    • pm2: --node-args="-r esm"
  • Load esm with “require” options of ava, mocha, nodemon, nyc, qunit, tape, and webpack.

    :bulb: Builtin require cannot sideload .mjs files. However, .js files can be sideloaded or .mjs files may be loaded with dynamic import.

Current Tags

  • 3.2.25                                ...           latest (7 months ago)

140 Versions

  • 3.2.25                                ...           7 months ago
  • 3.2.24                                ...           7 months ago
  • 3.2.23                                ...           7 months ago
  • 3.2.22                                ...           8 months ago
  • 3.2.21                                ...           8 months ago
  • 3.2.20                                ...           9 months ago
  • 3.2.19                                ...           9 months ago
  • 3.2.18                                ...           9 months ago
  • 3.2.17                                ...           9 months ago
  • 3.2.16                                ...           9 months ago
  • 3.2.15                                ...           9 months ago
  • 3.2.14                                ...           9 months ago
  • 3.2.13                                ...           9 months ago
  • 3.2.12                                ...           9 months ago
  • 3.2.11                                ...           9 months ago
  • 3.2.10                                ...           9 months ago
  • 3.2.9                                ...           9 months ago
  • 3.2.8                                ...           9 months ago
  • 3.2.7                                ...           9 months ago
  • 3.2.6                                ...           10 months ago
  • 3.2.5                                ...           10 months ago
  • 3.2.4                                ...           10 months ago
  • 3.2.3                                ...           10 months ago
  • 3.2.2                                ...           10 months ago
  • 3.2.1                                ...           10 months ago
  • 3.2.0                                ...           10 months ago
  • 3.1.4                                ...           10 months ago
  • 3.1.3                                ...           a year ago
  • 3.1.2                                ...           a year ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.84                                ...           a year ago
  • 3.0.83                                ...           a year ago
  • 3.0.82                                ...           a year ago
  • 3.0.81                                ...           a year ago
  • 3.0.80                                ...           a year ago
  • 3.0.79                                ...           a year ago
  • 3.0.78                                ...           a year ago
  • 3.0.77                                ...           a year ago
  • 3.0.76                                ...           a year ago
  • 3.0.75                                ...           a year ago
  • 3.0.74                                ...           a year ago
  • 3.0.73                                ...           a year ago
  • 3.0.72                                ...           a year ago
  • 3.0.71                                ...           a year ago
  • 3.0.70                                ...           a year ago
  • 3.0.69                                ...           a year ago
  • 3.0.68                                ...           a year ago
  • 3.0.67                                ...           a year ago
  • 3.0.66                                ...           a year ago
  • 3.0.65                                ...           a year ago
  • 3.0.64                                ...           a year ago
  • 3.0.63                                ...           a year ago
  • 3.0.62                                ...           a year ago
  • 3.0.61                                ...           a year ago
  • 3.0.60                                ...           a year ago
  • 3.0.59                                ...           a year ago
  • 3.0.58                                ...           a year ago
  • 3.0.56                                ...           a year ago
  • 3.0.57                                ...           a year ago
  • 3.0.55                                ...           a year ago
  • 3.0.54                                ...           a year ago
  • 3.0.53                                ...           a year ago
  • 3.0.52                                ...           a year ago
  • 3.0.51                                ...           a year ago
  • 3.0.50                                ...           a year ago
  • 3.0.49                                ...           2 years ago
  • 3.0.48                                ...           2 years ago
  • 3.0.47                                ...           2 years ago
  • 3.0.46                                ...           2 years ago
  • 3.0.45                                ...           2 years ago
  • 3.0.44                                ...           2 years ago
  • 3.0.43                                ...           2 years ago
  • 3.0.42                                ...           2 years ago
  • 3.0.41                                ...           2 years ago
  • 3.0.40                                ...           2 years ago
  • 3.0.39                                ...           2 years ago
  • 3.0.38                                ...           2 years ago
  • 3.0.37                                ...           2 years ago
  • 3.0.36                                ...           2 years ago
  • 3.0.35                                ...           2 years ago
  • 3.0.34                                ...           2 years ago
  • 3.0.33                                ...           2 years ago
  • 3.0.32                                ...           2 years ago
  • 3.0.31                                ...           2 years ago
  • 3.0.30                                ...           2 years ago
  • 3.0.29                                ...           2 years ago
  • 3.0.28                                ...           2 years ago
  • 3.0.27                                ...           2 years ago
  • 3.0.26                                ...           2 years ago
  • 3.0.25                                ...           2 years ago
  • 3.0.24                                ...           2 years ago
  • 3.0.23                                ...           2 years ago
  • 3.0.22                                ...           2 years ago
  • 3.0.21                                ...           2 years ago
  • 3.0.20                                ...           2 years ago
  • 3.0.19                                ...           2 years ago
  • 3.0.18                                ...           2 years ago
  • 3.0.17                                ...           2 years ago
  • 3.0.16                                ...           2 years ago
  • 3.0.15                                ...           2 years ago
  • 3.0.14                                ...           2 years ago
  • 3.0.13                                ...           2 years ago
  • 3.0.12                                ...           2 years ago
  • 3.0.11                                ...           2 years ago
  • 3.0.10                                ...           2 years ago
  • 3.0.9                                ...           2 years ago
  • 3.0.8                                ...           2 years ago
  • 3.0.7                                ...           2 years ago
  • 3.0.6                                ...           2 years ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           2 years ago
  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.2                                ...           3 years ago
  • 2.1.1                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.9                                ...           3 years ago
  • 2.0.8                                ...           3 years ago
  • 2.0.7                                ...           3 years ago
  • 2.0.6                                ...           3 years ago
  • 2.0.5                                ...           3 years ago
  • 2.0.4                                ...           3 years ago
  • 2.0.3                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 63
This Week 10,921
This Month 35,318
Last Day 4,144
Last Week 22,979
Last Month 80,523
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1807)

Copyright 2014 - 2016 © taobao.org |