{"id":13450,"library":"liferay-npm-bundler-plugin-namespace-packages","title":"Liferay npm Bundler Namespace Packages Plugin","description":"This plugin for `liferay-npm-bundler` modifies `package.json` files during the bundling process to prefix package names with the root project's name. This mechanism creates isolated dependency graphs for individual Liferay projects, effectively preventing dependency conflicts and ensuring predictable runtime behavior, particularly crucial when dealing with peer dependencies. It specifically targets package name entries and handles scoped packages by prepending the project's name to the scope (e.g., `@a-scope/a-package` becomes `@my-project$a-scope/a-package`). Introduced with `liferay-npm-bundler` 2.x to enable isolated dependencies, it addresses scenarios where package names need to be unique per bundle. The current stable version is 2.32.2. However, it is critical to note that its core dependency, `liferay-npm-bundler`, has been deprecated as of Liferay 2024.Q4/Portal GA129 and is slated for future removal, as Liferay shifts towards standard JavaScript tooling like esbuild, webpack, or vite. While still functional for existing Liferay DXP setups, its long-term relevance is diminishing. Its primary differentiator is providing project-level dependency sandboxing within the Liferay ecosystem, prioritizing stability and predictability over cross-project dependency deduplication.","status":"maintenance","version":"2.32.2","language":"javascript","source_language":"en","source_url":"https://github.com/liferay/liferay-frontend-projects","tags":["javascript"],"install":[{"cmd":"npm install liferay-npm-bundler-plugin-namespace-packages","lang":"bash","label":"npm"},{"cmd":"yarn add liferay-npm-bundler-plugin-namespace-packages","lang":"bash","label":"yarn"},{"cmd":"pnpm add liferay-npm-bundler-plugin-namespace-packages","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This plugin extends `liferay-npm-bundler` and requires it to function. Note that `liferay-npm-bundler` is deprecated.","package":"liferay-npm-bundler"},{"reason":"Strongly recommended as a counterpart plugin to fully namespace module `define()` and `require()` calls within JavaScript files, complementing this plugin's `package.json` modification.","package":"babel-plugin-namespace-modules","optional":true}],"imports":[{"note":"This plugin is configured as a string literal within the `plugins` array of a `.npmbundlerrc` configuration file, typically at the root level (`\"*\"`) to apply to all modules. It is not imported as a JavaScript or TypeScript module.","wrong":"import { namespacePackages } from 'liferay-npm-bundler-plugin-namespace-packages'","symbol":"\"namespace-packages\"","correct":"{\n  \"*\": {\n    \"plugins\": [\"namespace-packages\"]\n  }\n}"}],"quickstart":{"code":"npm install --save-dev liferay-npm-bundler-plugin-namespace-packages\n\n// Add the following to your .npmbundlerrc file in the project root\n// This enables the plugin for all modules within the bundler process.\n// Make sure to also configure babel-plugin-namespace-modules for full effect.\n{\n  \"*\": {\n    \"plugins\": [\"namespace-packages\"]\n  }\n}\n","lang":"json","description":"Demonstrates how to install the `liferay-npm-bundler-plugin-namespace-packages` via npm and configure it within the `.npmbundlerrc` file to enable project-level package namespacing for the Liferay npm bundler."},"warnings":[{"fix":"Plan to migrate your Liferay frontend projects away from `liferay-npm-bundler` and its plugins to modern JavaScript bundlers. Consult Liferay's official documentation for migration guides.","message":"The underlying `liferay-npm-bundler` tool, which this plugin extends, has been deprecated as of Liferay DXP 2024.Q4/Portal GA129 and is planned for future removal. Liferay recommends migrating to standard JavaScript tooling like esbuild, webpack, or vite.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Consult the changelogs for both `liferay-npm-bundler` and this plugin. Update to compatible versions as recommended by Liferay documentation.","message":"Major version updates of `liferay-npm-bundler` may introduce breaking changes to its plugin API, potentially requiring an update to this plugin for compatibility.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Understand that this is a design choice for stability. Profile your bundle if size is a critical concern, but generally accept this trade-off for Liferay projects requiring strict dependency isolation.","message":"This plugin intentionally disables cross-project package deduplication to ensure dependency isolation and stability. This can lead to increased bundle sizes.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure `babel-plugin-namespace-modules` is correctly configured in your Babel pipeline when using this bundler plugin to achieve full module isolation.","message":"For complete module sandboxing, this plugin should be used in conjunction with `babel-plugin-namespace-modules`. Without its Babel counterpart, only `package.json` entries are namespaced, not actual `define()` or `require()` calls within the JavaScript code.","severity":"gotcha","affected_versions":"*"},{"fix":"Always verify the package name. The correct installation command is `npm install --save-dev liferay-npm-bundler-plugin-namespace-packages`.","message":"Some documentation or examples might incorrectly reference a different plugin during installation (e.g., `liferay-npm-bundler-plugin-inject-angular-dependencies`).","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install and configure `babel-plugin-namespace-modules` in your Babel configuration to ensure module identifiers within code are also namespaced.","cause":"The `babel-plugin-namespace-modules` is not configured, meaning module `import`/`require` statements are not rewritten to match the namespaced package names.","error":"ModuleNotFoundError: Cannot find module 'my-scoped-package' after namespacing plugin enabled."},{"fix":"This is expected behavior and a trade-off for increased stability and predictability in Liferay environments. Evaluate if the isolation benefits justify the increased bundle size for your use case.","cause":"The `liferay-npm-bundler-plugin-namespace-packages` intentionally prevents package deduplication across different projects to ensure strict isolation, leading to larger bundle sizes.","error":"Bundled output size significantly larger than expected after enabling namespacing."},{"fix":"Double-check that your `.npmbundlerrc` file contains `\"plugins\": [\"namespace-packages\"]` under the appropriate configuration scope (e.g., `\"*\"`). Verify that your build process correctly invokes `liferay-npm-bundler` with this configuration.","cause":"The plugin is either not correctly specified in the `.npmbundlerrc` file's `plugins` array, or the `liferay-npm-bundler` itself is not executing with the correct configuration.","error":"Plugin does not seem to be applied, package names in output bundles are not modified."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}