{"id":19248,"library":"babel-plugin-wrap-modules-amd","title":"babel-plugin-wrap-modules-amd","description":"A Babel plugin (v2.32.2, last released 2024-03-05) that wraps CommonJS modules inside AMD define() calls. It automatically detects require() calls and adds them as AMD dependencies, removing the need for manual dependency arrays. Part of the Liferay Frontend Projects monorepo, maintained for liferay-portal build system. Infrequently updated; stable but low community adoption outside Liferay. Requires Babel 6/7 and the plugin must be listed in .babelrc. No active development seen in recent years.","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 babel-plugin-wrap-modules-amd","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-wrap-modules-amd","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-wrap-modules-amd","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Plugin is CommonJS internally but can be imported via ESM in Babel config when using module system.","wrong":"const plugin = require('babel-plugin-wrap-modules-amd'); // CJS require","symbol":"default","correct":"import plugin from 'babel-plugin-wrap-modules-amd'; // ESM"},{"note":"Plugin does not export a named symbol; only default export is available.","wrong":"import wrapModuleAmdPlugin from 'babel-plugin-wrap-modules-amd';","symbol":"wrapModuleAmdPlugin","correct":"import { wrapModuleAmdPlugin } from 'babel-plugin-wrap-modules-amd';"},{"note":"Babel resolves short plugin name; the full npm package name is not required.","wrong":"module.exports = { plugins: ['babel-plugin-wrap-modules-amd'] };","symbol":"babel.config.js usage","correct":"module.exports = { plugins: ['wrap-modules-amd'] };"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"wrap-modules-amd\"]\n}\n\n// Input file (source.js)\nvar fs = require('fs');\nconsole.log(fs.readFileSync('data.txt', 'utf8'));\n\n// After Babel transformation, output becomes:\ndefine(['module', 'exports', 'require', 'fs'], function (module, exports, require) {\n  var fs = require('fs');\n  console.log(fs.readFileSync('data.txt', 'utf8'));\n});\n","lang":"javascript","description":"Shows how to configure the plugin in .babelrc and its effect: a CommonJS module with require() gets wrapped in an AMD define() call with dependencies auto-detected."},"warnings":[{"fix":"Use Babel plugin-transform-modules-commonjs first if using ES import syntax.","message":"Plugin only supports CommonJS require() calls; does not handle dynamic imports or ES modules.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"If you need named modules, use a different plugin like babel-plugin-amd-define.","message":"The plugin does not support named AMD modules; define() always uses anonymous definition.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use a modern bundler that outputs AMD if needed, or adopt a different output format.","message":"Maintenance mode; no new features planned. Consider migrating to modern bundlers like Webpack or Rollup if possible.","severity":"deprecated","affected_versions":">=2.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-wrap-modules-amd and ensure node_modules path is correct.","cause":"The plugin is not installed, or Node.js cannot resolve it when running Babel.","error":"Error: Cannot find module 'babel-plugin-wrap-modules-amd'"},{"fix":"Include an AMD loader such as RequireJS, or use the plugin to output CommonJS instead.","cause":"The wrapped AMD module is executed in an environment without an AMD loader (like RequireJS).","error":"ReferenceError: define is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}