Registry / devops / babel-plugin-namespace-modules

babel-plugin-namespace-modules

JSON →
library2.32.2jsnpmunverified

A Babel plugin that prepends the root project's package name and version to AMD module names in define() and require() calls, preventing module name clashes across projects. This is particularly useful for sandboxing dependencies in Liferay environments, ensuring runtime dependencies match development dependencies. Version 2.32.2 is the latest stable release, maintained as part of the liferay-frontend-projects monorepo. It integrates with liferay-npm-bundler for consistent namespace handling.

npm install babel-plugin-namespace-modules
INSTALL
IMPORT
SIG · BABEL-PLUGIN-NAMES
B
babel-plugin-namespace-modules
devopsjavascriptv2.32.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
module.exports = require('babel-plugin-namespace-modules')
import plugin from 'babel-plugin-namespace-modules'
CJS module, use require() for Node.js; ESM import may fail without transformation
BabelPluginNamespaceModules
const plugin = require('babel-plugin-namespace-modules')
const { BabelPluginNamespaceModules } = require('babel-plugin-namespace-modules')
Only default export is available; destructuring will yield undefined
plugin as .babelrc
{ "plugins": ["namespace-modules"] }
{ "plugins": ["babel-plugin-namespace-modules"] }
Babel plugin name in .babelrc is 'namespace-modules', not the full package name

Shows basic installation and .babelrc configuration for namespace AMD modules with root project name.

// Install and configure in .babelrc to namespace AMD modules // Ensure @babel/core is installed: npm install --save-dev @babel/core // .babelrc { "plugins": ["namespace-modules"] } // Example code: define('my-module', ['dep'], function(dep) { return dep; }); // After transpilation: define('my-project$my-module', ['my-project$dep'], function(dep) { return dep; });
Debug
Known issues
gotchaPlugin only works with AMD-style define() and require() calls (e.g., from RequireJS). CommonJS or ES modules are not affected.
fix
Ensure your code uses AMD syntax or use a different plugin for CommonJS/ESM.
affects: >=0.0.0
gotchaRelative module paths (starting with './') are not namespaced, which may cause unexpected sharing of local modules.
fix
Use absolute-looking module names if you want them namespaced, or configure a different plugin.
affects: >=0.0.0
breakingScoped package names are modified: '@scope/pkg' becomes '@my-project$scope/pkg' (prefix without '@'). This changes the module name significantly.
fix
Update any hardcoded references to scoped modules to match the new pattern.
affects: >=2.0.0
deprecatedThe plugin is primarily designed for Liferay ecosystem and may not receive updates for non-Liferay setups.
fix
Consider using general-purpose module naming plugins if outside Liferay.
affects: >=2.32.2
Errors
Common errors & fixes
Module not found: Can't resolve 'babel-plugin-namespace-modules'
Missing npm install or incorrect plugin name in Babel config.
fix
Run: npm install --save-dev babel-plugin-namespace-modules
Error: Plugin . is not a valid plugin, or is already loaded
Using full package name 'babel-plugin-namespace-modules' instead of short name 'namespace-modules' in .babelrc.
fix
Use: { "plugins": ["namespace-modules"] }
TypeError: Cannot read property 'someModule' of undefined
Module named with a scoped package '@scope/pkg' is referenced without the plugin's transformation, causing alias mismatch.
fix
Ensure the plugin is applied and all AMD define/require calls use the namespaced name.
Upgrade
Version history
2.32.2latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency required to register as a Babel plugin
Agent activity
7 hits · last 30 days
node
7
Resources
babel-plugin-namespace-modules — npm install babel-plugin-namespace-modules · libregistry