{"id":26775,"library":"babel-plugin-name-amd-modules","title":"babel-plugin-name-amd-modules","description":"A Babel plugin that gives a name to AMD modules based on the module's path and package name. Version 2.32.2 is the current stable release. This plugin is maintained by Liferay and is part of the JS Toolkit ecosystem. It is specifically designed for AMD module systems, automatically generating named define() calls using package name and relative path. Unlike generic AMD plugins, it integrates with Liferay's build tooling and respects .npmbundlerrc configuration. Release cadence is irregular, with version bumps tied to the monorepo releases. Works with Babel 7+ and is intended for legacy AMD codebases or custom module systems.","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-name-amd-modules","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-name-amd-modules","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-name-amd-modules","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to function as a Babel plugin","package":"@babel/core","optional":true}],"imports":[{"note":"Used as a Babel plugin string 'name-amd-modules' in config, not imported directly unless building custom Babel config programmatically.","wrong":"import plugin from 'babel-plugin-name-amd-modules';","symbol":"default","correct":"module.exports = require('babel-plugin-name-amd-modules'); // in .babelrc plugin array"},{"note":"The plugin name in Babel config is the short form without the 'babel-plugin-' prefix, per Babel convention.","wrong":"{\n  \"plugins\": [\"babel-plugin-name-amd-modules\"]\n}","symbol":"name-amd-modules","correct":"// In .babelrc or babel.config.js:\n{\n  \"plugins\": [\"name-amd-modules\"]\n}"},{"note":"For programmatic Babel config (babel.config.js), use require as the plugin is CJS-only. No default ES import is supported.","wrong":"import plugin from 'babel-plugin-name-amd-modules';","symbol":"require('babel-plugin-name-amd-modules')","correct":"module.exports = function(api) {\n  api.cache(true);\n  const plugin = require('babel-plugin-name-amd-modules');\n  return { plugins: [plugin] };\n};"}],"quickstart":{"code":"// 1. Install\n// npm install --save-dev babel-plugin-name-amd-modules\n\n// 2. Configure .babelrc\n{\n  \"plugins\": [\n    [\n      \"name-amd-modules\",\n      {\n        \"packageName\": \"my-package\",\n        \"srcPrefixes\": [\"src\"]\n      }\n    ]\n  ]\n}\n\n// 3. Input file (src/index.js):\ndefine(['dep'], function(dep) {\n  // module code\n});\n\n// 4. Build output:\ndefine('my-package@1.0.0/index', ['dep'], function(dep) {\n  // module code\n});","lang":"javascript","description":"Shows installation, configuration with packageName and srcPrefixes, input AMD define and transformed output with named module."},"warnings":[{"fix":"Ensure define() calls always have at least two arguments: dependencies array and factory function.","message":"Plugin only transforms AMD define() calls that match the exact pattern; anonymous define() without second argument (dependency array) may not be processed.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Set packageName explicitly in plugin options to avoid relying on automatic detection.","message":"The default packageName reads from package.json, which may be fragile in monorepo setups without proper source prefixes.","severity":"deprecated","affected_versions":"<=2.32.2"},{"fix":"Ensure define is a global in the code being transformed; avoid importing define from another module.","message":"The plugin expects AMD define to be a global function; if define is imported from a library (e.g., requirejs), the plugin may not recognize it.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Explicitly configure srcPrefixes option to include all applicable source directories.","message":"In version 2.x, source prefixes from .npmbundlerrc are automatically applied only when transforming files inside those directories; files outside may get incorrect relative paths.","severity":"breaking","affected_versions":">=2.0.0 <2.32.0"},{"fix":"Use extensionless module paths in define() calls (e.g., define('pkg@1.0.0/index', ...)).","message":"The plugin removes the .js extension from the module name; do NOT include .js in imports as it will cause mismatches.","severity":"gotcha","affected_versions":">=1.0.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-name-amd-modules' to install the plugin.","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'babel-plugin-name-amd-modules'"},{"fix":"Use '\"plugins\": [\"name-amd-modules\"]' without the 'babel-plugin-' prefix.","cause":"Incorrect plugin name in Babel config (used full name 'babel-plugin-name-amd-modules' instead of short form).","error":"Plugin name-amd-modules not found"},{"fix":"Set srcPrefixes option to include the directory containing the file, or ensure package.json exists and is valid.","cause":"Plugin is processing a file outside the configured srcPrefixes or with missing package.json.","error":"TypeError: Cannot read property 'relativePath' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}