Registry / testing / babel-plugin-webpack-aliases

babel-plugin-webpack-aliases

JSON →
library1.1.3jsnpmunverified

Babel 6 plugin that resolves webpack resolve.alias during Babel transpilation, useful for testing environments where webpack is not available. Version 1.1.3 (stable, last release 2016). It replaces require/import paths with relative paths based on webpack config aliases. Maintained as a fork of babel-plugin-webpack-alias. No updates since 2016; consider alternatives like module-resolver for newer Babel versions.

npm install babel-plugin-webpack-aliases
INSTALL
IMPORT
SIG · BABEL-PLUGIN-WEBPA
B
babel-plugin-webpack-aliases
testingjavascriptv1.1.3
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.

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';
Debug
Known issues
deprecatedPlugin is no longer maintained and only supports Babel 6. Not compatible with Babel 7+.
fix
Migrate to babel-plugin-module-resolver for Babel 7+ compat.
affects: >=1.0.0
gotchaPlugin expects webpack config to export an object. If using webpack-merge or other patterns, alias resolution may fail.
fix
Ensure webpack config is a plain object. Use require() to load config and verify resolve.alias exists.
affects: >=1.0.0
gotchaAlias resolution is relative to the webpack config file location, not the project root.
fix
Use absolute paths in webpack aliases with path.resolve(__dirname, ...) to avoid confusion.
affects: >=1.0.0
gotchaDoes not support webpack resolve.alias fields with arrays or nested objects; only simple key-value string mappings.
fix
Flatten complex alias configurations into simple string mappings.
affects: >=1.0.0
gotchaIf findConfig option is true, plugin uses find-up but does not handle multiple matching configs well.
fix
Explicitly set config path to avoid ambiguity.
affects: >=1.0.0
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.
fix
Check 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.
fix
Ensure 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.
fix
Do not import the plugin directly; use it only within Babel configuration.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
find-upoptionalOptional dependency to locate webpack config file using find-up if findConfig option is set.
Agent activity
22 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
babel-plugin-webpack-aliases — npm install babel-plugin-webpack-aliases · libregistry