A Babel plugin for transforming ESM modules to AMD modules, designed to work with RequireJS and the requirejs-babel7 plugin. Current stable version 0.2.0 (May 2025). It replaces the combination of @babel/plugin-transform-modules-amd, babel-plugin-amd-checker, babel-plugin-amd-default-export, and babel-plugin-module-resolver-standalone, solving limitations around mixing ESM and AMD modules at any dependency level and handling default exports without wrapping. Supports customising module path resolution via a resolvePath function. Infrequent releases; maintained by a single author.
npm install babel-plugin-transform-modules-requirejs-babelVerified import paths — ran on the pinned version, not inferred.
Shows basic Babel configuration with the plugin, optional resolvePath customization, and expected AMD output from an ESM module.
Upgrade to >=0.0.4 which fixes recognition of AMD modules without dependencies.
Always check sourcePath against 'require', 'module', 'exports' in resolvePath, as shown in the example.
Remove '@babel/plugin-transform-modules-amd', 'babel-plugin-amd-checker', 'babel-plugin-amd-default-export', 'babel-plugin-module-resolver-standalone' and use this plugin instead.
Update consuming AMD modules to treat direct exports as the default value; if you need the wrapper, set the addDefaultProperty option (not yet implemented) or use babel-plugin-amd-default-export with addDefaultProperty: true before this plugin.
Run `npm install -D babel-plugin-transform-modules-requirejs-babel` to install it as a dev dependency.
Provide a function: `resolvePath(sourcePath, currentFile) { ... }` not a string like 'es6!source'.Ensure the plugin is listed in your Babel config under 'plugins' (not 'presets') and that Babel is running on the file. Example: `plugins: ['transform-modules-requirejs-babel']`.
Include RequireJS script before your compiled modules. Example: `<script src='require.js' data-main='main'></script>`.