{"id":19176,"library":"babel-plugin-transform-amd-to-es6","title":"babel-plugin-transform-amd-to-es6","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/cgkineo/babel-plugin-transform-amd-to-es6","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-transform-amd-to-es6","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-amd-to-es6","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-amd-to-es6","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for plugin to function; must be installed alongside.","package":"@babel/core","optional":false}],"imports":[{"note":"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.","wrong":"import babelPluginTransformAmdToEs6 from 'babel-plugin-transform-amd-to-es6'","symbol":"default (plugin)","correct":"module.exports = function() { return { plugins: ['transform-amd-to-es6'] }; };"},{"note":"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.","wrong":"plugins: ['transform-amd-to-es6', { umdToAMDModules: true }]","symbol":"plugin with options","correct":"plugins: [['transform-amd-to-es6', { umdToAMDModules: true }]]"},{"note":"The plugin automatically converts AMD return statements to export default. No manual symbol import needed.","wrong":"// Not an import; the plugin handles the transformation automatically.","symbol":"default export from AMD","correct":"// In Babel config: plugins: [['transform-amd-to-es6', { defineFunctionName: '__AMD' }]];\n// In AMD module: return { foo: 'bar' };\n// becomes: export default { foo: 'bar' };"}],"quickstart":{"code":"// .babelrc.js\nmodule.exports = {\n  plugins: [\n    [\n      'transform-amd-to-es6',\n      {\n        umdToAMDModules: true,\n        amdToES6Modules: true,\n        amdDefineES6Modules: true,\n        ignoreNestedRequires: true,\n        defineFunctionName: '__AMD',\n        defineModuleId: (moduleId) => moduleId.replace(/^path\\//, ''),\n        ignores: []\n      }\n    ]\n  ]\n};\n\n// Example AMD input (module.js):\ndefine('myModule', ['dep1', 'dep2'], function(dep1, dep2) {\n  return {\n    greet: function() { console.log(dep1.name); }\n  };\n});\n\n// Transformed output:\nimport dep1 from 'dep1';\nimport dep2 from 'dep2';\nconst __AMD__default = {\n  greet: function() { console.log(dep1.name); }\n};\nexport default __AMD__default;\n__AMD('myModule', __AMD__default);","lang":"javascript","description":"Converts AMD module (define with dependencies and return) into ES6 import/export with optional AMD registration client-side."},"warnings":[{"fix":"Use defineModuleId option to map your AMD module IDs to actual file paths (e.g., strip prefixes).","message":"Module IDs must match filenames for correct resolution after transformation.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test your UMD modules individually; disable umdToAMDModules if you only have native AMD.","message":"If umdToAMDModules is enabled, the plugin may not correctly handle plain UMD patterns that don't follow the expected AMD wrapper.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to Babel 7 (@babel/core). Babel 6 users should use alternative plugins or manual conversion.","message":"The plugin is designed for Babel 7; does not support Babel 6.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Choose a unique function name (e.g., '__registerAMD') to avoid collisions.","message":"The defineFunctionName option conflicts with existing code if another global uses the same function name (default '__AMD').","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set ignoreNestedRequires: false if you need nested requires converted to dynamic import().","message":"Nested require() calls inside AMD modules may not be transformed unless ignoreNestedRequires is set to false.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev @babel/core","cause":"@babel/core is not installed or not in node_modules.","error":"Error: Plugin transform-amd-to-es6: Cannot find module '@babel/core'"},{"fix":"Use ['transform-amd-to-es6', { options }] inside the plugins array, not ['transform-amd-to-es6', { options }] as separate arguments.","cause":"Incorrect nested options syntax in Babel config (options passed as a separate array element).","error":"Error: Unknown option: .umdToAMDModules. Check if it is valid."},{"fix":"Ensure the plugin runs after any syntax plugins. Reorder your Babel plugins: place 'transform-amd-to-es6' last.","cause":"The plugin received a non-AMD syntax or a malformed AST node. May occur with plugins that modify AST before this one.","error":"TypeError: Cannot read property 'body' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}