Registry / devops / babel-plugin-transform-barrels

babel-plugin-transform-barrels

JSON →
library1.0.23jsnpmunverified

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.

npm install babel-plugin-transform-barrels
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-barrels
devopsjavascriptv1.0.23
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin)
module.exports = require('babel-plugin-transform-barrels'); // or in babel config: plugins: [['babel-plugin-transform-barrels', { executorName: 'webpack' }]]
import plugin from 'babel-plugin-transform-barrels'; // Not meant for consumer code
This is a Babel plugin, not a library to import in application code. It is added to babel config as a string name.
babelTransform
const babelTransform = require('./config/jest/babelTransform');
import { babelTransform } from 'babel-plugin-transform-barrels';
The babelTransform.js file is provided in the package's config folder and should be copied to your project.
Options
// In babel.config.js: module.exports = { plugins: [['babel-plugin-transform-barrels', { executorName: 'jest', alias: { '@': './src' } }]] };
// Using wrong executorName like 'webpack' for Jest, or omitting executorName
Options are passed as the second element of the plugin array. executorName is required for proper behavior.

Shows installation, basic configuration with all options, and an example import transformation.

// 1. Install // npm install --save-dev babel-plugin-transform-barrels // 2. babel.config.js module.exports = { plugins: [ ['babel-plugin-transform-barrels', { executorName: 'webpack', // or 'jest' or 'vite' alias: { '@': './src' }, extensions: ['.js', '.jsx', '.ts', '.tsx'], modulesDirs: ['node_modules'], moduleIgnorePatterns: [], isCacheEnabled: false }] ] }; // 3. Before: import { Button, List } from './components'; // After: import { Button } from './components/Button/Button'; // import { List } from './components/List/List';
Debug
Known issues
breakingIn v1.0.16, the options 'webpackAlias' and 'jestAlias' were replaced by a single 'alias' option. Similarly, 'webpackExtensions' and 'jestExtensions' were replaced by 'extensions'.
fix
Update your config to use 'alias' and 'extensions' instead of the old option names.
affects: <1.0.16
breakingThe '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.
fix
Use 'babel-plugin-transform-barrels' as the plugin name in your babel config.
affects: all
gotchaThe plugin only transforms imports that go through a barrel file (index.js). If your import is already direct, it is not modified.
fix
Ensure you have barrel files (index.js) that re-export modules, and that imports point to the barrel directory.
affects: all
gotchaJest 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.
fix
Set executorName to 'jest' when using Jest.
affects: all
gotchaThe plugin uses caching (file-based) when isCacheEnabled is true. Cache may cause stale transformations if barrel files change without version increment.
fix
Clear cache manually (e.g., delete the .cache folder) or disable caching during development.
affects: >=1.0.14
Errors
Common errors & fixes
Error: [BABEL] unknown: The 'executorName' option is required.
Missing executorName option in plugin configuration.
fix
Add executorName: 'webpack' (or 'jest' or 'vite') to the plugin options.
Error: Module not found: Can't resolve './components' in '/path/to/src'
The barrel file (index.js) does not exist or the import path is incorrect.
fix
Create an index.js file in the components folder that re-exports the desired modules, or correct the import path.
Error: [BABEL] unknown: The 'alias' option should be an object.
Passed a non-object value for alias (e.g., string or array).
fix
Ensure alias is an object with string keys and values, e.g., { '@': './src' }.
Error: Cannot find module 'babel-plugin-transform-barrels'
The package is not installed or not in node_modules.
fix
Run npm install --save-dev babel-plugin-transform-barrels.
Upgrade
Version history
1.0.23latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-transform-barrels — npm install babel-plugin-transform-barrels · libregistry