ES6 Module Transpiler AMD Formatter

raw JSON →
0.3.0 verified Fri May 01 auth: no javascript maintenance

An output formatter plugin for es6-module-transpiler that compiles ES6 module syntax into AMD define() format supported by RequireJS. Version 0.3.0 is the latest stable release; the project is in maintenance mode with no active development. It converts subsets of ES6 module syntax (import/export) into AMD-compatible code, supporting default exports, named exports, and re-exports. Unlike other transpilers like Babel, this plugin is tightly coupled to the now-deprecated es6-module-transpiler ecosystem and requires esprima for parsing. It compromises on ES6 features like live bindings and sealed objects to enable AMD compatibility. Requires Node.js and the es6-module-transpiler package at version 0.10.x.

error Error: Cannot find module 'es6-module-transpiler-amd-formatter'
cause The package is not installed or not in the Node module resolution path.
fix
Run npm install es6-module-transpiler-amd-formatter in your project directory.
error TypeError: formatter is not a constructor
cause Using the formatter module incorrectly (e.g., calling it as a function instead of using `new`).
fix
Use new (require('es6-module-transpiler-amd-formatter'))() to instantiate the formatter.
error Error: Unknown formatter 'es6-module-transpiler-amd-formatter'
cause The CLI -f flag expects the formatter module name, but the module cannot be loaded (likely not installed).
fix
Install the package globally or locally, and ensure the module name is correct.
deprecated es6-module-transpiler is no longer maintained. The AMD formatter only works with es6-module-transpiler and will not receive updates.
fix Migrate to a modern transpiler like Babel with @babel/plugin-transform-modules-amd.
breaking Version 0.3.0 requires es6-module-transpiler 0.10.x. Using an older version of the transpiler will cause errors.
fix Ensure es6-module-transpiler is at version ^0.10.0.
gotcha The AMD formatter does not support live bindings or sealed objects as per ES6 specification. Exports are snapshots.
fix Avoid relying on live bindings; treat exports as static values.
gotcha The formatter cannot be used standalone; it must be passed as an option to es6-module-transpiler Container or CLI.
fix Always install and import es6-module-transpiler along with this formatter.
npm install es6-module-transpiler-amd-formatter
yarn add es6-module-transpiler-amd-formatter
pnpm add es6-module-transpiler-amd-formatter

Shows how to use the AMD formatter with the es6-module-transpiler Container API to compile ES6 modules from 'lib/' into an AMD define() output file.

// Install dependencies
// npm install es6-module-transpiler es6-module-transpiler-amd-formatter

var transpiler = require('es6-module-transpiler');
var AMDFormatter = require('es6-module-transpiler-amd-formatter');
var Container = transpiler.Container;
var FileResolver = transpiler.FileResolver;

var container = new Container({
  resolvers: [new FileResolver(['lib/'])],
  formatter: new AMDFormatter()
});

container.getModule('index');
container.write('out/mylib.js');