Registry / http-networking / babel-plugin-transform-modules-requirejs-babel

babel-plugin-transform-modules-requirejs-babel

JSON →
library0.2.0jsnpmunverified

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-babel
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-modules-requirejs-babel
http-networkingjavascriptv0.2.0
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
module.exports = { plugins: ['transform-modules-requirejs-babel'] }
import transformModulesRequirejsBabel from 'babel-plugin-transform-modules-requirejs-babel'
The plugin is used as a string in Babel config, not imported directly. Use the plugin name in .babelrc or babel.config.js.
resolvePath
['transform-modules-requirejs-babel', { resolvePath: (source, currentFile) => 'es6!' + source }]
plugins: [['babel-plugin-transform-modules-requirejs-babel', { resolvePath: 'es6!' }]]
resolvePath must be a function, not a string. It receives sourcePath and currentFile arguments.
Plugin as CommonJS require
const plugin = require('babel-plugin-transform-modules-requirejs-babel'); module.exports = { plugins: [plugin] }
const plugin = require('babel-plugin-transform-modules-requirejs-babel').default
This plugin is CJS-compatible. Using .default would be incorrect as it's not an ESM default export.

Shows basic Babel configuration with the plugin, optional resolvePath customization, and expected AMD output from an ESM module.

// Install: npm i -D babel-plugin-transform-modules-requirejs-babel // .babelrc or babel.config.js module.exports = { presets: [], plugins: [ // Basic usage: no options 'transform-modules-requirejs-babel' ] }; // Optionally with custom resolvePath: // plugins: [ // [ // 'transform-modules-requirejs-babel', // { // resolvePath(sourcePath, currentFile) { // if (sourcePath.indexOf('!') < 0 && sourcePath !== 'require' && // sourcePath !== 'module' && sourcePath !== 'exports') { // return 'es6!' + sourcePath; // } // } // } // ] // ] // Example ESM input 'src/main.js': // import { helper } from './helper'; // export default function main() { helper(); } // After Babel transformation (AMD output): // define('src/main', ['./helper'], function (_helper) { // 'use strict'; // function main() { (0, _helper.helper)(); } // return main; // });
Debug
Known issues
gotchaThe plugin assumes that AMD modules without dependencies (empty define) are not mixed with ESM; if you have AMD modules with no deps, they may be transformed incorrectly.
fix
Upgrade to >=0.0.4 which fixes recognition of AMD modules without dependencies.
affects: <0.0.4
gotchaResolvePath function must handle the three pseudo-modules 'require', 'module', 'exports' explicitly to avoid prefixing them.
fix
Always check sourcePath against 'require', 'module', 'exports' in resolvePath, as shown in the example.
affects: >=0.0.0
deprecatedThis plugin replaces a combination of four other plugins; if you are using those, migrate to this single plugin to avoid conflicts and missing features.
fix
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.
affects: >=0.1.0
breakingThe plugin now transforms default exports without wrapping in { default: ... } to keep compatibility with RequireJS. This may break code expecting the default property wrapper.
fix
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.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Module 'babel-plugin-transform-modules-requirejs-babel' not found
The plugin is not installed or is missing from node_modules.
fix
Run `npm install -D babel-plugin-transform-modules-requirejs-babel` to install it as a dev dependency.
TypeError: resolvePath is not a function
The resolvePath option was provided as a string instead of a function.
fix
Provide a function: `resolvePath(sourcePath, currentFile) { ... }` not a string like 'es6!source'.
SyntaxError: Unexpected token 'export'
Babel is not configured to transpile ES modules; the plugin may not be applied.
fix
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']`.
ReferenceError: define is not defined
The AMD module output expects RequireJS to be loaded in the browser, but RequireJS is not present.
fix
Include RequireJS script before your compiled modules. Example: `<script src='require.js' data-main='main'></script>`.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
@babel/corerequiredBabel plugin requires @babel/core to function; peer dependency.
requirejsoptionalRuntime dependency for loading AMD modules in the browser; required for execution.
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
2
Resources
babel-plugin-transform-modules-requirejs-babel — npm install babel-plugin-transform-modules-requirejs-babel · libregistry