ES6 Module Transpiler
raw JSON → 0.3.1 verified Fri May 01 auth: no javascript deprecated
es6-module-transpiler is an experimental compiler that allows writing JavaScript using a subset of the current ES6 module syntax, compiling it into AMD or CommonJS modules. Version 0.3.1 is the latest stable release. It provides a way to experiment with ES6 module syntax in real-world scenarios. Key differentiators: closely tracks TC39 module proposals, supports both AMD and CommonJS output, and provides a command-line interface. Note: This project is experimental and may not follow semver; syntax may change.
Common errors
error Error: Cannot find module 'es6-module-transpiler' ↓
cause Package not published to npm; must use git URL.
fix
Install from git: npm install -g https://git.squareup.com/javascript/es6-module-transpiler
error compile-modules command not found ↓
cause Global install failed or not in PATH.
fix
Ensure global npm modules path is in PATH, or use npx.
error SyntaxError: Unexpected token 'export' ↓
cause Using ES6 module syntax in a non-transpiled environment.
fix
Run the code through the transpiler first, or use a runtime that supports ES modules.
Warnings
deprecated This package is not actively maintained and the ES6 module spec has changed significantly since its creation. ↓
fix Use a more up-to-date transpiler like Babel or TypeScript.
breaking Syntax may not match finalized ES6 modules; expect incompatibilities. ↓
fix Refer to current ES module spec or use modern tools.
gotcha When using 'globals' type, you must provide --imports mapping for all imported modules. ↓
fix Supply --imports like '--imports ember:Ember' or equivalent options hash.
gotcha The '--module-name' option cannot be used with multiple input files. ↓
fix Either use single file or omit --module-name.
gotcha The package is hosted on a private GitHub URL; not available via npm registry. ↓
fix Install directly from git: npm install -g <git-url>
Install
npm install es6-module-transpiler-rewrite yarn add es6-module-transpiler-rewrite pnpm add es6-module-transpiler-rewrite Imports
- Compiler wrong
import { Compiler } from 'es6-module-transpiler';correctvar Compiler = require('es6-module-transpiler').Compiler; - Container
var Container = require('es6-module-transpiler').Container; - Compiler class wrong
var compiler = new Compiler(string);correctvar compiler = new Compiler(string, name, options);
Quickstart
// Install globally (use git URL as npm package not published)
// $ npm install -g https://git.squareup.com/javascript/es6-module-transpiler
// Create an ES6 module file (example.js):
// export var foo = 'bar';
// Compile to AMD:
// $ compile-modules example.js --to dist --type amd
// Or use as library:
var Compiler = require('es6-module-transpiler').Compiler;
var code = 'export var foo = "bar";';
var compiler = new Compiler(code, 'example');
var amdOutput = compiler.toAMD();
console.log(amdOutput);
// Outputs: define('example', [], function() { ... });