{"id":19221,"library":"babel-plugin-transform-require-context","title":"babel-plugin-transform-require-context","description":"Babel plugin (v0.1.1) to transform webpack's `require.context()` into dummy function calls, allowing code to run outside webpack (e.g., in Node.js or Jest). It does not resolve files or perform dynamic requires—only prevents breakage. No releases since 2019; minimal maintenance. Use when migrating webpack code to non-webpack environments.","status":"maintenance","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/asapach/babel-plugin-transform-require-context","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-transform-require-context","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-require-context","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-require-context","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required at runtime to apply the plugin","package":"@babel/core","optional":false}],"imports":[{"note":"CommonJS export; no default export. Use require() or import with destructuring.","symbol":"transformRequireContext","correct":"module.exports = require('babel-plugin-transform-require-context')"},{"note":"Plugin is exported as a function directly via module.exports. Named import does not exist.","wrong":"import { transformRequireContext } from 'babel-plugin-transform-require-context'","symbol":"default","correct":"import plugin from 'babel-plugin-transform-require-context'"},{"note":"Babel resolves the short name automatically; using full package name also works but verbose.","wrong":"\"plugins\": [\"babel-plugin-transform-require-context\"]","symbol":"babel config string","correct":"\"plugins\": [\"transform-require-context\"]"}],"quickstart":{"code":"// In .babelrc or babel.config.js\n{\n  \"plugins\": [\"transform-require-context\"]\n}\n\n// Input code (webpack-specific)\nconst req = require.context('./locale', true, /\\.json$/);\n\n// Output code (transformed)\nvar req = function() { return {}; }; // dummy, no file lookup\n\n// Run via API\nconst babel = require('@babel/core');\nconst result = babel.transformSync('const req = require.context(\"./locale\", true, /\\.json$/);', {\n  plugins: ['transform-require-context']\n});\nconsole.log(result.code);\n// Outputs: var req = function() { return {}; };","lang":"javascript","description":"Shows plugin setup via .babelrc and Node API, input with require.context, and transformed dummy function."},"warnings":[{"fix":"Use mock data or actual file system resolution outside webpack.","message":"Plugin does not actually load or resolve files; it only prevents runtime errors. Code expecting real files will still fail.","severity":"gotcha","affected_versions":">=0"},{"fix":"If your code accesses .keys() or iterates results, adjust for empty object.","message":"The dummy function returns an empty object, not an array like webpack's require.context would.","severity":"gotcha","affected_versions":">=0"},{"fix":"Consider alternatives like webpack's require.context stub or manual mocking.","message":"Package is in maintenance mode with no recent updates; may not support newer Babel versions (especially Babel 8).","severity":"deprecated","affected_versions":">=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 babel-plugin-transform-require-context --save-dev`","cause":"Plugin not installed or missing from node_modules","error":"Error: Cannot find module 'babel-plugin-transform-require-context'"},{"fix":"Use mock that matches webpack's API: `module.exports = (function() { var ctx = { keys: () => [] }; return ctx; })`","cause":"Assuming require.context returns an array or has .keys(), but plugin returns an empty object","error":"TypeError: Cannot read property 'keys' of undefined"},{"fix":"Update to @babel/core >=7.0.0","cause":"Using outdated Babel version that expects function export; plugin returns object","error":"Plugin/Preset files are not allowed to export objects, only functions."},{"fix":"Ensure context calls happen inside code bundled by webpack, or use a different transform","cause":"Running code in environment without CommonJS require (e.g., browser without bundler). Plugin transforms webpack's require.context, not Node's require","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}