{"id":19177,"library":"babel-plugin-transform-barrels","title":"babel-plugin-transform-barrels","description":"A Babel plugin that transforms indirect imports through barrel files (index.js) into direct imports. Current stable version is 1.0.23. The plugin supports Webpack, Vite, and Jest, resolving imports to improve bundling performance and avoid circular dependencies. Key differentiators include support for package.json exports field, jest.mock/requireActual, Webpack aliases, and caching. It is designed to be used as a Babel plugin with minimal configuration, offering options like alias, extensions, modulesDirs, and moduleIgnorePatterns. Version 1.0.23 adds moduleIgnorePatterns and fixes jest.mock bugs.","status":"active","version":"1.0.23","language":"javascript","source_language":"en","source_url":"https://github.com/FogelAI/babel-plugin-transform-barrels","tags":["javascript","barrel","babel","plugin","transform","import","webpack","jest","index"],"install":[{"cmd":"npm install babel-plugin-transform-barrels","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-barrels","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-barrels","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a Babel plugin, not a library to import in application code. It is added to babel config as a string name.","wrong":"import plugin from 'babel-plugin-transform-barrels'; // Not meant for consumer code","symbol":"default (plugin)","correct":"module.exports = require('babel-plugin-transform-barrels');\n// or in babel config: plugins: [['babel-plugin-transform-barrels', { executorName: 'webpack' }]]"},{"note":"The babelTransform.js file is provided in the package's config folder and should be copied to your project.","wrong":"import { babelTransform } from 'babel-plugin-transform-barrels';","symbol":"babelTransform","correct":"const babelTransform = require('./config/jest/babelTransform');"},{"note":"Options are passed as the second element of the plugin array. executorName is required for proper behavior.","wrong":"// Using wrong executorName like 'webpack' for Jest, or omitting executorName","symbol":"Options","correct":"// In babel.config.js:\nmodule.exports = { plugins: [['babel-plugin-transform-barrels', { executorName: 'jest', alias: { '@': './src' } }]] };"}],"quickstart":{"code":"// 1. Install\n// npm install --save-dev babel-plugin-transform-barrels\n\n// 2. babel.config.js\nmodule.exports = {\n  plugins: [\n    ['babel-plugin-transform-barrels', {\n      executorName: 'webpack', // or 'jest' or 'vite'\n      alias: { '@': './src' },\n      extensions: ['.js', '.jsx', '.ts', '.tsx'],\n      modulesDirs: ['node_modules'],\n      moduleIgnorePatterns: [],\n      isCacheEnabled: false\n    }]\n  ]\n};\n\n// 3. Before: import { Button, List } from './components';\n// After: import { Button } from './components/Button/Button';\n//         import { List } from './components/List/List';","lang":"javascript","description":"Shows installation, basic configuration with all options, and an example import transformation."},"warnings":[{"fix":"Update your config to use 'alias' and 'extensions' instead of the old option names.","message":"In v1.0.16, the options 'webpackAlias' and 'jestAlias' were replaced by a single 'alias' option. Similarly, 'webpackExtensions' and 'jestExtensions' were replaced by 'extensions'.","severity":"breaking","affected_versions":"<1.0.16"},{"fix":"Use 'babel-plugin-transform-barrels' as the plugin name in your babel config.","message":"The 'babel-plugin-transform-barrels' plugin name must be used in babel config; using 'transform-barrels' without the 'babel-plugin-' prefix may not work in some setups.","severity":"breaking","affected_versions":"all"},{"fix":"Ensure you have barrel files (index.js) that re-export modules, and that imports point to the barrel directory.","message":"The plugin only transforms imports that go through a barrel file (index.js). If your import is already direct, it is not modified.","severity":"gotcha","affected_versions":"all"},{"fix":"Set executorName to 'jest' when using Jest.","message":"Jest mock calls: jest.mock('./components') will be transformed to jest.mock('./components/Button/Button') only if executorName is 'jest'. Without correct executorName, transformation may not work.","severity":"gotcha","affected_versions":"all"},{"fix":"Clear cache manually (e.g., delete the .cache folder) or disable caching during development.","message":"The plugin uses caching (file-based) when isCacheEnabled is true. Cache may cause stale transformations if barrel files change without version increment.","severity":"gotcha","affected_versions":">=1.0.14"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add executorName: 'webpack' (or 'jest' or 'vite') to the plugin options.","cause":"Missing executorName option in plugin configuration.","error":"Error: [BABEL] unknown: The 'executorName' option is required."},{"fix":"Create an index.js file in the components folder that re-exports the desired modules, or correct the import path.","cause":"The barrel file (index.js) does not exist or the import path is incorrect.","error":"Error: Module not found: Can't resolve './components' in '/path/to/src'"},{"fix":"Ensure alias is an object with string keys and values, e.g., { '@': './src' }.","cause":"Passed a non-object value for alias (e.g., string or array).","error":"Error: [BABEL] unknown: The 'alias' option should be an object."},{"fix":"Run npm install --save-dev babel-plugin-transform-barrels.","cause":"The package is not installed or not in node_modules.","error":"Error: Cannot find module 'babel-plugin-transform-barrels'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}