amd-to-es6
raw JSON → 0.2.0 verified Fri May 01 auth: no javascript abandoned
A CLI and programmatic tool to convert AMD modules (define pattern) into ES6 module syntax. Current version 0.2.0, last updated in 2014. It handles simple cases like modules with/without dependencies and imports for side-effects, but does NOT support named define modules, multiple define per file, or UMD patterns. The library is effectively abandoned as there are more modern alternatives like jscodeshift or lebab, and no updates since 2014. It works by parsing AMD define calls and rewriting to import/export statements, with options for directory batch processing, glob patterns, and beautification via jsbeautify.
Common errors
error TypeError: convert is not a function ↓
cause Incorrect import or using require on an ESM-only package.
fix
Use import { convert } from 'amd-to-es6' instead of require.
error Error: Unsupported define format ↓
cause Named define modules or UMD patterns not supported.
fix
Remove the name from define('name', ...) or rewrite UMD to anonymous define.
error SyntaxError: Unexpected token ↓
cause Input contains multiple define calls or invalid AMD syntax.
fix
Ensure each file has exactly one define call with a function literal callback.
Warnings
deprecated Package is unmaintained since 2014; no support for modern JavaScript features or fixes. ↓
fix Consider using jscodeshift or lebab for AMD to ES6 conversion.
breaking Does not support named define modules; those will throw an error or be silently skipped. ↓
fix Manually rename named defines to anonymous before conversion or use an alternative tool.
breaking Does not support UMD modules where define callback is not a function literal (e.g., define(factoryFn)). ↓
fix Rewrite UMD modules to plain AMD define patterns before conversion.
gotcha Generated variable names for dynamic requires use ugly prefixes like $__path_to_a, which may break coding standards. ↓
fix Manually rename generated variable names after conversion.
breaking The package is ESM-only; using require() will fail with ReferenceError or undefined. ↓
fix Use import syntax and ensure your Node.js version supports ESM, or transpile your code.
Install
npm install amd-to-es6 yarn add amd-to-es6 pnpm add amd-to-es6 Imports
- convert wrong
var convert = require('amd-to-es6')correctimport { convert } from 'amd-to-es6' - default wrong
const amdToEs6 = require('amd-to-es6').defaultcorrectimport amdToEs6 from 'amd-to-es6' - convertSync
import { convertSync } from 'amd-to-es6'
Quickstart
import { convert } from 'amd-to-es6';
const amdCode = `define(['path/to/a', 'path/to/b'], function (a, b) {
return function (x) {
return a(b(x));
};
});`;
try {
const es6Code = convert(amdCode);
console.log(es6Code);
} catch (error) {
console.error('Conversion failed:', error.message);
}