Registry / web-framework / babel-plugin-name-amd-modules

babel-plugin-name-amd-modules

JSON →
library2.32.2jsnpmunverified

A Babel plugin that gives a name to AMD modules based on the module's path and package name. Version 2.32.2 is the current stable release. This plugin is maintained by Liferay and is part of the JS Toolkit ecosystem. It is specifically designed for AMD module systems, automatically generating named define() calls using package name and relative path. Unlike generic AMD plugins, it integrates with Liferay's build tooling and respects .npmbundlerrc configuration. Release cadence is irregular, with version bumps tied to the monorepo releases. Works with Babel 7+ and is intended for legacy AMD codebases or custom module systems.

npm install babel-plugin-name-amd-modules
INSTALL
IMPORT
SIG · BABEL-PLUGIN-NAME-
B
babel-plugin-name-amd-modules
web-frameworkjavascriptv2.32.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
module.exports = require('babel-plugin-name-amd-modules'); // in .babelrc plugin array
import plugin from 'babel-plugin-name-amd-modules';
Used as a Babel plugin string 'name-amd-modules' in config, not imported directly unless building custom Babel config programmatically.
name-amd-modules
// In .babelrc or babel.config.js: { "plugins": ["name-amd-modules"] }
{ "plugins": ["babel-plugin-name-amd-modules"] }
The plugin name in Babel config is the short form without the 'babel-plugin-' prefix, per Babel convention.
require('babel-plugin-name-amd-modules')
module.exports = function(api) { api.cache(true); const plugin = require('babel-plugin-name-amd-modules'); return { plugins: [plugin] }; };
import plugin from 'babel-plugin-name-amd-modules';
For programmatic Babel config (babel.config.js), use require as the plugin is CJS-only. No default ES import is supported.

Shows installation, configuration with packageName and srcPrefixes, input AMD define and transformed output with named module.

// 1. Install // npm install --save-dev babel-plugin-name-amd-modules // 2. Configure .babelrc { "plugins": [ [ "name-amd-modules", { "packageName": "my-package", "srcPrefixes": ["src"] } ] ] } // 3. Input file (src/index.js): define(['dep'], function(dep) { // module code }); // 4. Build output: define('my-package@1.0.0/index', ['dep'], function(dep) { // module code });
Debug
Known issues
gotchaPlugin only transforms AMD define() calls that match the exact pattern; anonymous define() without second argument (dependency array) may not be processed.
fix
Ensure define() calls always have at least two arguments: dependencies array and factory function.
affects: >=2.0.0
deprecatedThe default packageName reads from package.json, which may be fragile in monorepo setups without proper source prefixes.
fix
Set packageName explicitly in plugin options to avoid relying on automatic detection.
affects: <=2.32.2
gotchaThe plugin expects AMD define to be a global function; if define is imported from a library (e.g., requirejs), the plugin may not recognize it.
fix
Ensure define is a global in the code being transformed; avoid importing define from another module.
affects: >=2.0.0
breakingIn version 2.x, source prefixes from .npmbundlerrc are automatically applied only when transforming files inside those directories; files outside may get incorrect relative paths.
fix
Explicitly configure srcPrefixes option to include all applicable source directories.
affects: >=2.0.0 <2.32.0
gotchaThe plugin removes the .js extension from the module name; do NOT include .js in imports as it will cause mismatches.
fix
Use extensionless module paths in define() calls (e.g., define('pkg@1.0.0/index', ...)).
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-name-amd-modules'
Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev babel-plugin-name-amd-modules' to install the plugin.
Plugin name-amd-modules not found
Incorrect plugin name in Babel config (used full name 'babel-plugin-name-amd-modules' instead of short form).
fix
Use '"plugins": ["name-amd-modules"]' without the 'babel-plugin-' prefix.
TypeError: Cannot read property 'relativePath' of undefined
Plugin is processing a file outside the configured srcPrefixes or with missing package.json.
fix
Set srcPrefixes option to include the directory containing the file, or ensure package.json exists and is valid.
Upgrade
Version history
2.32.2latest on npm
Audit
Dependencies
@babel/coreoptionalpeer dependency required to function as a Babel plugin
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
babel-plugin-name-amd-modules — npm install babel-plugin-name-amd-modules · libregistry