{"id":19016,"library":"babel-plugin-add-module-metadata","title":"babel-plugin-add-module-metadata","description":"A Babel plugin for the Liferay ecosystem that scans JavaScript modules for predefined code patterns and adds corresponding metadata entries to the manifest.json file generated by the liferay-npm-bundler. Version 2.32.2 is the latest stable release, maintained as part of the liferay-frontend-projects monorepo with monthly to quarterly releases. Unlike generic Babel plugins, this one is tailored specifically for Liferay's AMD module system, enabling module description prior to load or parse. It is used in conjunction with the Liferay JS Toolkit and npm bundler.","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-add-module-metadata","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-add-module-metadata","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-add-module-metadata","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency because the plugin is a Babel transformation.","package":"@babel/core","optional":false},{"reason":"The plugin's output (manifest.json) is consumed by the bundler; without it, the plugin is useless.","package":"liferay-npm-bundler","optional":false}],"imports":[{"note":"This is a Babel plugin designed for CommonJS; it should be used in .babelrc or babel.config.js as a string 'add-module-metadata'. Direct import/export is rare but if needed, use require() for CJS.","wrong":"import plugin from 'babel-plugin-add-module-metadata'; export default plugin;","symbol":"default","correct":"module.exports = function() { return { visitor: { ... } }; };"},{"note":"Babel resolves the plugin name without the 'babel-plugin-' prefix when listed in .babelrc or babel.config.js.","wrong":"plugins: ['babel-plugin-add-module-metadata']","symbol":"add-module-metadata","correct":"plugins: ['add-module-metadata']"},{"note":"You can require and pass the plugin as an object, but the simpler string form is recommended.","wrong":"import plugin from 'babel-plugin-add-module-metadata'; plugins: [plugin];","symbol":"babel-plugin-add-module-metadata","correct":"const plugin = require('babel-plugin-add-module-metadata'); plugins: [plugin];"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"add-module-metadata\"]\n}\n\n// Example input (to trigger metadata generation):\n// file: src/foo.js\nLiferay.Loader.define('my-module', ['exports', 'require'], function(exports, require) {\n  'use strict';\n  exports.default = 'hello';\n});\n\n// After building with liferay-npm-bundler, manifest.json will include:\n// {\n//   \"packages\": {\n//     \"my-module\": {\n//       \"metadata\": { ... }\n//     }\n//   }\n// }","lang":"javascript","description":"Shows minimal .babelrc configuration and the expected transformation from an AMD module to manifest.json metadata."},"warnings":[{"fix":"Ensure liferay-npm-bundler is part of your build process.","message":"This plugin only works in conjunction with liferay-npm-bundler. Without it, no manifest.json is generated.","severity":"gotcha","affected_versions":"*"},{"fix":"Use Liferay.Loader.define or compatible AMD module definitions.","message":"Plugin does nothing if the code does not follow Liferay's AMD module patterns. Standard ES modules are not scanned.","severity":"gotcha","affected_versions":"*"},{"fix":"Check liferay-npm-bundler version. If using bundler v2+, consider migrating to the latest js-toolkit.","message":"The older manifest.json format (v1) was deprecated in liferay-npm-bundler v2.0. Newer plugins generate v2 metadata but this plugin may not be updated for v2 format.","severity":"deprecated","affected_versions":">=2.30.0"}],"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-add-module-metadata` and ensure it's in node_modules.","cause":"Missing or incorrect installation of the plugin.","error":"Error: Cannot find module 'babel-plugin-add-module-metadata'"},{"fix":"Use the string syntax: `plugins: ['add-module-metadata']`.","cause":"Passing the plugin string instead of a function in a JavaScript config file that expects function references.","error":"TypeError: plugin is not a function"},{"fix":"Use `module.exports = { plugins: ['add-module-metadata'] };` instead of `export default`.","cause":"Using ES module syntax in a Babel config file that is treated as CommonJS.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}