{"id":19220,"library":"babel-plugin-transform-require-default","title":"babel-plugin-transform-require-default","description":"A Babel plugin (v0.1.7, last updated 2018) that automatically transforms CommonJS require() calls to access .default for ES modules that use __esModule. Addresses Babel 6/7's breaking change where exported defaults are no longer assigned to module.exports, requiring manual .default access. Helps maintain backward compatibility in mixed ES module / CommonJS codebases. Use with caution: modifies module resolution behavior and may cause unintended side effects. Consider alternatives like using ES import syntax or newer Babel interop settings.","status":"maintenance","version":"0.1.7","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/kingback/babel-plugin-transform-require-default","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-transform-require-default","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-require-default","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-require-default","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The plugin exports a function, not an object. It does not have a default export; it's a CommonJS module.","wrong":"require('babel-plugin-transform-require-default').default","symbol":"default","correct":"module.exports = { plugins: [['transform-require-default', { exclude: /lodash/ }]] }"}],"quickstart":{"code":"// .babelrc or babel.config.js\nmodule.exports = {\n  plugins: [\n    ['transform-require-default', {\n      exclude: ['lodash', /^react/]\n    }]\n  ]\n};\n\n// Before:\nconst a = require('a');\n\n// After:\nfunction __require_default_func__(module) { return module && module.__esModule ? module[\"default\"] : module; }\nconst a = __require_default_func__(require('a'));","lang":"javascript","description":"Configures the Babel plugin to transform require() calls, excluding certain modules, and shows the result of the transformation."},"warnings":[{"fix":"Use exclude option to skip modules that don't need default interop (e.g., lodash, React).","message":"Plugin modifies all require() calls to add default interop, which may break modules that don't export defaults or that rely on the raw module object.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Ensure all affected modules set __esModule, or use exclude to skip them.","message":"Plugin uses __esModule heuristic; modules that don't set __esModule but have a default export will still be transformed, causing 'default.default' access.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use static require() calls if you need transformation.","message":"Plugin does not handle dynamic require() with variables or computed expressions.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Test carefully with your plugin stack, and adjust plugin ordering.","message":"Plugin may interfere with other Babel plugins that also transform require (e.g., babel-plugin-import).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add the module to the exclude list: exclude: [\"my-module\"]","cause":"Module exports a function directly, not as default export. Plugin incorrectly adds .default.","error":"TypeError: require(...).default is not a function"},{"fix":"Use exclude: ['lodash'] or set strict mode.","cause":"Plugin transforms require('lodash') to require('lodash').default, but lodash doesn't have __esModule.","error":"Module \"lodash\" has no default export"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}