AMD to ES6 module transpiler

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

A CLI and programmatic tool to convert AMD modules (RequireJS style) into ES6 module syntax. Version 0.2.5 is the latest, released mid-2015, with no recent updates. It handles dependencies, default exports, and side-effect imports, but does not support named define, multiple defines per file, or UMD patterns. It offers options for directory conversion, file ignore patterns, and beautification via jsbeautify. Key differentiator: simple, focused conversion without bundling or transpilation of other ES6 features. Compared to alternatives like lebab or jscodeshift, this is minimal and specific.

error Error: Unsupported define pattern
cause The file contains a named define, multiple defines, or a non-literal callback function.
fix
Ensure the define call has no name, only one define per file, and the callback is a function literal.
error TypeError: convert is not a function
cause Incorrect import: using default import instead of named import.
fix
Use const { convert } = require('amd-to-es6'); or import { convert } from 'amd-to-es6';
error Cannot find module 'js-beautify'
cause The --beautify option requires js-beautify, which is an optional dependency not installed by default in some environments.
fix
Install js-beautify globally or locally: npm install js-beautify
gotcha Named define modules are not supported (e.g., define('my-module', ...)). Attempting to convert such files will result in a skip or error.
fix Remove the module name from the define call before conversion.
gotcha Files with multiple module definitions are not supported. Only one define per file is converted; others are ignored.
fix Split files so each contains a single define.
gotcha UMD style modules where the callback is not a function literal (e.g., define(factoryFn)) are not supported.
fix Rewrite UMD modules to use a literal function in the define callback.
deprecated The package has not been updated since 2015. It may not work with modern Node.js versions or newer JavaScript syntax.
fix Consider using alternative tools like lebab or manual conversion.
npm install amd-to-es6-other
yarn add amd-to-es6-other
pnpm add amd-to-es6-other

Shows how to use the programmatic API to convert a single AMD module string to ES6 syntax.

const { convert } = require('amd-to-es6');
const amdCode = `define(['path/to/a'], function (a) { return function (x) { return a(x); }; });`;
const es6Code = convert(amdCode);
console.log(es6Code);
// Output:
// import a from 'path/to/a';
// export default function (x) { return a(x); };