{"id":19108,"library":"babel-plugin-namespace-modules","title":"babel-plugin-namespace-modules","description":"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.","status":"active","version":"2.32.2","language":"javascript","source_language":"en","source_url":"https://github.com/liferay/liferay-frontend-projects","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-namespace-modules","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-namespace-modules","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-namespace-modules","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required to register as a Babel plugin","package":"@babel/core","optional":false}],"imports":[{"note":"CJS module, use require() for Node.js; ESM import may fail without transformation","wrong":"import plugin from 'babel-plugin-namespace-modules'","symbol":"default","correct":"module.exports = require('babel-plugin-namespace-modules')"},{"note":"Only default export is available; destructuring will yield undefined","wrong":"const { BabelPluginNamespaceModules } = require('babel-plugin-namespace-modules')","symbol":"BabelPluginNamespaceModules","correct":"const plugin = require('babel-plugin-namespace-modules')"},{"note":"Babel plugin name in .babelrc is 'namespace-modules', not the full package name","wrong":"{\n  \"plugins\": [\"babel-plugin-namespace-modules\"]\n}","symbol":"plugin as .babelrc","correct":"{\n  \"plugins\": [\"namespace-modules\"]\n}"}],"quickstart":{"code":"// Install and configure in .babelrc to namespace AMD modules\n// Ensure @babel/core is installed: npm install --save-dev @babel/core\n// .babelrc\n{\n  \"plugins\": [\"namespace-modules\"]\n}\n// Example code: define('my-module', ['dep'], function(dep) { return dep; });\n// After transpilation: define('my-project$my-module', ['my-project$dep'], function(dep) { return dep; });","lang":"javascript","description":"Shows basic installation and .babelrc configuration for namespace AMD modules with root project name."},"warnings":[{"fix":"Ensure your code uses AMD syntax or use a different plugin for CommonJS/ESM.","message":"Plugin only works with AMD-style define() and require() calls (e.g., from RequireJS). CommonJS or ES modules are not affected.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use absolute-looking module names if you want them namespaced, or configure a different plugin.","message":"Relative module paths (starting with './') are not namespaced, which may cause unexpected sharing of local modules.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update any hardcoded references to scoped modules to match the new pattern.","message":"Scoped package names are modified: '@scope/pkg' becomes '@my-project$scope/pkg' (prefix without '@'). This changes the module name significantly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Consider using general-purpose module naming plugins if outside Liferay.","message":"The plugin is primarily designed for Liferay ecosystem and may not receive updates for non-Liferay setups.","severity":"deprecated","affected_versions":">=2.32.2"}],"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-plugin-namespace-modules","cause":"Missing npm install or incorrect plugin name in Babel config.","error":"Module not found: Can't resolve 'babel-plugin-namespace-modules'"},{"fix":"Use: { \"plugins\": [\"namespace-modules\"] }","cause":"Using full package name 'babel-plugin-namespace-modules' instead of short name 'namespace-modules' in .babelrc.","error":"Error: Plugin . is not a valid plugin, or is already loaded"},{"fix":"Ensure the plugin is applied and all AMD define/require calls use the namespaced name.","cause":"Module named with a scoped package '@scope/pkg' is referenced without the plugin's transformation, causing alias mismatch.","error":"TypeError: Cannot read property 'someModule' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}