{"id":13448,"library":"liferay-npm-bundler-plugin-inject-peer-dependencies","title":"Liferay npm Bundler Peer Dependency Injection Plugin","description":"This package, `liferay-npm-bundler-plugin-inject-peer-dependencies`, is a plugin for `liferay-npm-bundler` that automates the injection of peer and undeclared dependencies into `package.json` files. It specifically targets dependencies found within AMD `define()` calls in module files, provided they are installed in `node_modules`. This functionality is crucial for ensuring peer dependencies operate correctly within Liferay's OSGi-based npm architecture and can also resolve certain incorrect setups that might otherwise work in a standard Node.js environment. The plugin determines dependency versions using the standard Node.js resolution algorithm from the module's context. The current stable version is 2.32.2. As part of the broader `liferay-frontend-projects` monorepo, its release cadence is tied to Liferay's development cycles, with frequent updates across various tooling components. Its key differentiator is its specialized function within the Liferay ecosystem, addressing specific challenges of module loading and dependency resolution in that platform.","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 liferay-npm-bundler-plugin-inject-peer-dependencies","lang":"bash","label":"npm"},{"cmd":"yarn add liferay-npm-bundler-plugin-inject-peer-dependencies","lang":"bash","label":"yarn"},{"cmd":"pnpm add liferay-npm-bundler-plugin-inject-peer-dependencies","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a plugin for the liferay-npm-bundler and requires it to function. It is configured via the `.npmbundlerrc` file used by the bundler.","package":"liferay-npm-bundler","optional":false}],"imports":[{"note":"This package is a bundler plugin and is configured declaratively in the `.npmbundlerrc` file, not imported directly into JavaScript/TypeScript code. The string 'inject-peer-dependencies' refers to the plugin's name within the bundler's context.","wrong":"import InjectPeerDependenciesPlugin from 'liferay-npm-bundler-plugin-inject-peer-dependencies';","symbol":"Configuring the plugin","correct":"/* In your .npmbundlerrc */\n{\n\t\"*\": {\n\t\t\"plugins\": [\"inject-peer-dependencies\"]\n\t}\n}"},{"note":"Options for the plugin are passed as an array where the first element is the plugin name string and the second is an object containing the configuration properties.","symbol":"Configuring with options","correct":"/* In your .npmbundlerrc */\n{\n\t\"*\": {\n\t\t\"plugins\": [\n\t\t\t[\n\t\t\t\t\"inject-peer-dependencies\",\n\t\t\t\t{\n\t\t\t\t\t\"defineCall\": \"Liferay.Loader.define\"\n\t\t\t\t}\n\t\t\t]\n\t\t]\n\t}\n}"}],"quickstart":{"code":"{\n\t\"*\": {\n\t\t\"plugins\": [\n\t\t\t[\n\t\t\t\t\"inject-peer-dependencies\",\n\t\t\t\t{\n\t\t\t\t\t\"defineCall\": \"Liferay.Loader.define\"\n\t\t\t\t}\n\t\t\t]\n\t\t]\n\t},\n\t\"test-module\": {\n\t\t\"dependencies\": {\n\t\t\t\"lodash\": \"*\"\n\t\t}\n\t}\n}\n\n// Example package.json for a module that would benefit from this plugin\n/*\n{\n  \"name\": \"my-liferay-module\",\n  \"version\": \"1.0.0\",\n  \"peerDependencies\": {\n    \"react\": \"^17.0.0\"\n  },\n  \"devDependencies\": {\n    \"liferay-npm-bundler-plugin-inject-peer-dependencies\": \"^2.0.0\",\n    \"liferay-npm-bundler\": \"^2.0.0\"\n  }\n}\n*/\n\n// Example module.js content where 'react' would be detected as a peer dependency\n/*\ndefine([\"react\", \"./MyComponent\"], function(React, MyComponent) {\n  return function App() {\n    return React.createElement(MyComponent, null, \"Hello\");\n  };\n});\n*/","lang":"json","description":"This quickstart demonstrates how to configure the `inject-peer-dependencies` plugin within a `.npmbundlerrc` file, showing both basic inclusion and inclusion with custom options like `defineCall`. It also contextualizes its use with illustrative package.json and module file content."},"warnings":[{"fix":"Ensure all peer and undeclared dependencies are explicitly listed in your module's `package.json` and installed via `npm install` or `yarn install` before running the bundler.","message":"The plugin only injects dependencies if they are already installed in `node_modules` and listed in the project's `package.json`. It does not automatically install missing packages.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only use this plugin when developing modules for Liferay portals, where the `liferay-npm-bundler` is the primary build tool.","message":"This plugin is specifically designed for the Liferay npm architecture and may not be necessary or function as expected in other bundling contexts. It relies on the AMD `define()` pattern for dependency detection.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to the latest `liferay-npm-bundler` and `liferay-npm-bundler-plugin-inject-peer-dependencies` to ensure compatibility and leverage the most current features and fixes. Review changelogs for specific breaking changes in major versions.","message":"Older versions of `liferay-npm-bundler` or this plugin might have different resolution algorithms or configuration options for `defineCall` or similar properties. Always consult the specific version's documentation.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Verify the `defineCall` option matches the actual AMD define function used by your Liferay environment. The default `Liferay.Loader.define` is common, but custom setups might vary.","message":"Misconfigured `defineCall` (e.g., if Liferay's loader is customized) can prevent the plugin from correctly identifying AMD dependencies, leading to missed injections.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Check that '<dependency-name>' is listed in the `dependencies`, `devDependencies`, or `peerDependencies` section of your module's `package.json` and that `npm install` has been run successfully.","cause":"The bundler could not find a required dependency in `node_modules` or `package.json`, even after the injection plugin ran.","error":"Error: Missing dependency '<dependency-name>' in module '<module-name>'"},{"fix":"Ensure the plugin is installed as a `devDependency` (`npm install --save-dev liferay-npm-bundler-plugin-inject-peer-dependencies`) and that `liferay-npm-bundler` is correctly configured to find plugins.","cause":"The `liferay-npm-bundler-plugin-inject-peer-dependencies` package is not installed or not accessible to the bundler.","error":"Plugin 'inject-peer-dependencies' not found"},{"fix":"Verify the `defineCall` option in `.npmbundlerrc` is correct. Inspect the generated bundle to see if the dependency was actually injected. Manually check the module's AMD `define()` calls for any non-standard syntax.","cause":"Despite the plugin, the bundler or runtime still cannot resolve a dependency, potentially due to incorrect path resolution or an unusual `define()` call.","error":"Module not found: Error: Can't resolve '<dependency>' in '<path>'"}],"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}