Registry / type-stubs / babel-plugin-transform-amd-to-es6

babel-plugin-transform-amd-to-es6

JSON →
library1.0.2jsnpmunverified

Convert AMD modules (define/require) to ES6 import/export statements using a Babel plugin. Current version 1.0.2, maintained via automated releases. Key differentiator: supports complex AMD patterns including UMD, nested requires, and custom module ID mapping. Provides an option to register ES6 exports as AMD modules for client-side RequireJS compatibility using a configurable define function. Designed for projects migrating from AMD to ES modules while retaining client-side AMD loader support. Alternatives include amd-to-es6 and manual conversion scripts, but this plugin integrates directly into Babel 7 pipelines.

npm install babel-plugin-transform-amd-to-es6
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-amd-to-es6
type-stubsjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin)
module.exports = function() { return { plugins: ['transform-amd-to-es6'] }; };
import babelPluginTransformAmdToEs6 from 'babel-plugin-transform-amd-to-es6'
This is a Babel plugin, not a runtime import. It is used in Babel config via string reference or require() in .babelrc or babel.config.js.
plugin with options
plugins: [['transform-amd-to-es6', { umdToAMDModules: true }]]
plugins: ['transform-amd-to-es6', { umdToAMDModules: true }]
Options must be passed as an array inside the plugins array: ['plugin-name', options]. The common mistake is to pass options as a separate argument.
default export from AMD
// In Babel config: plugins: [['transform-amd-to-es6', { defineFunctionName: '__AMD' }]]; // In AMD module: return { foo: 'bar' }; // becomes: export default { foo: 'bar' };
// Not an import; the plugin handles the transformation automatically.
The plugin automatically converts AMD return statements to export default. No manual symbol import needed.

Converts AMD module (define with dependencies and return) into ES6 import/export with optional AMD registration client-side.

// .babelrc.js module.exports = { plugins: [ [ 'transform-amd-to-es6', { umdToAMDModules: true, amdToES6Modules: true, amdDefineES6Modules: true, ignoreNestedRequires: true, defineFunctionName: '__AMD', defineModuleId: (moduleId) => moduleId.replace(/^path\//, ''), ignores: [] } ] ] }; // Example AMD input (module.js): define('myModule', ['dep1', 'dep2'], function(dep1, dep2) { return { greet: function() { console.log(dep1.name); } }; }); // Transformed output: import dep1 from 'dep1'; import dep2 from 'dep2'; const __AMD__default = { greet: function() { console.log(dep1.name); } }; export default __AMD__default; __AMD('myModule', __AMD__default);
Debug
Known issues
gotchaModule IDs must match filenames for correct resolution after transformation.
fix
Use defineModuleId option to map your AMD module IDs to actual file paths (e.g., strip prefixes).
affects: >=1.0.0
gotchaIf umdToAMDModules is enabled, the plugin may not correctly handle plain UMD patterns that don't follow the expected AMD wrapper.
fix
Test your UMD modules individually; disable umdToAMDModules if you only have native AMD.
affects: >=1.0.0
deprecatedThe plugin is designed for Babel 7; does not support Babel 6.
fix
Upgrade to Babel 7 (@babel/core). Babel 6 users should use alternative plugins or manual conversion.
affects: >=1.0.0
gotchaThe defineFunctionName option conflicts with existing code if another global uses the same function name (default '__AMD').
fix
Choose a unique function name (e.g., '__registerAMD') to avoid collisions.
affects: >=1.0.0
gotchaNested require() calls inside AMD modules may not be transformed unless ignoreNestedRequires is set to false.
fix
Set ignoreNestedRequires: false if you need nested requires converted to dynamic import().
affects: >=1.0.0
Errors
Common errors & fixes
Error: Plugin transform-amd-to-es6: Cannot find module '@babel/core'
@babel/core is not installed or not in node_modules.
fix
Run npm install --save-dev @babel/core
Error: Unknown option: .umdToAMDModules. Check if it is valid.
Incorrect nested options syntax in Babel config (options passed as a separate array element).
fix
Use ['transform-amd-to-es6', { options }] inside the plugins array, not ['transform-amd-to-es6', { options }] as separate arguments.
TypeError: Cannot read property 'body' of undefined
The plugin received a non-AMD syntax or a malformed AST node. May occur with plugins that modify AST before this one.
fix
Ensure the plugin runs after any syntax plugins. Reorder your Babel plugins: place 'transform-amd-to-es6' last.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency required for plugin to function; must be installed alongside.
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
babel-plugin-transform-amd-to-es6 — npm install babel-plugin-transform-amd-to-es6 · libregistry