Registry /
testing / babel-plugin-webpack-aliases
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
plugin
✓ Add to .babelrc plugins array: ['babel-plugin-webpack-aliases', { config: './webpack.config.js' }]
✗ import babelPluginWebpackAliases from 'babel-plugin-webpack-aliases'
This is a Babel plugin, not a JavaScript module. It is used via .babelrc or babel.config.js, not imported directly.
plugin
✓ In babel.config.js: plugins: [['babel-plugin-webpack-aliases', { config: './webpack.config.js' }]]
✗ require('babel-plugin-webpack-aliases') in code
The plugin is configured in Babel config, not required in application code.
plugin
✓ In package.json babel section: "plugins": [["babel-plugin-webpack-aliases", { "config": "webpack.config.js" }]]
✗ Incorrect inline plugin syntax without array
When using string shorthand, arguments are passed as an array: [pluginName, options].
Configure plugin in .babelrc with webpack config path; aliases are resolved to relative paths.
// .babelrc
{
"plugins": [
["babel-plugin-webpack-aliases", {
"config": "./webpack.config.js"
}]
]
}
// webpack.config.js
module.exports = {
resolve: {
alias: {
'@components': './src/components',
'@utils': './src/utils'
}
}
};
// After Babel transpilation:
// import MyComponent from '@components/MyComponent';
// becomes:
// import MyComponent from './src/components/MyComponent';
Errors
Common errors & fixes
Module not found: Can't resolve '...' in '...'
Alias path not correctly resolved because webpack config path is wrong or alias mapping is incorrect.
fixCheck the config option points to the correct webpack config file and that aliases are configured with absolute paths.
TypeError: Cannot read property 'alias' of undefined
Webpack config does not have a resolve.alias property or config export is invalid.
fixEnsure webpack config exports an object with resolve.alias defined.
Error: Options must be a string, an array, or an object
Usage of babel-plugin-webpack-aliases outside of Babel config, e.g., as a module import.
fixDo not import the plugin directly; use it only within Babel configuration.
Audit
Dependencies
find-upoptionalOptional dependency to locate webpack config file using find-up if findConfig option is set.