Registry / testing / jest-webpack-alias

jest-webpack-alias

JSON →
library3.3.4jsnpmunverified

Jest preprocessor that resolves require() statements using webpack aliases. Version 3.3.4 (latest, no stable release cadence). Allows Jest to understand webpack alias resolution, but is deprecated in favor of babel-plugin-module-resolver. Handles JavaScript and non-JavaScript files through mocks, but AST limitations prevent dynamic require() resolution. Works with webpack multi-compiler profiles. Limited to webpack 1/2/3 style configurations.

npm install jest-webpack-alias
INSTALL
IMPORT
SIG · JEST-WEBPACK-ALIAS
J
jest-webpack-alias
testingjavascriptv3.3.4
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.

jest-webpack-alias
require('jest-webpack-alias')
import webpackAlias from 'jest-webpack-alias'
CommonJS module; only works with require, not ESM default import.
resolve
const { resolve } = require('jest-webpack-alias')
const resolve = require('jest-webpack-alias').resolve
Exported member for manual resolution of dynamic requires.

Shows the typical setup for a Jest preprocessor that applies babel-jest and webpack alias resolution.

// __tests__/preprocessor.js var babelJest = require('babel-jest'); require('babel-register'); var webpackAlias = require('jest-webpack-alias'); module.exports = { process: function(src, filename) { if (filename.indexOf('node_modules') === -1) { src = babelJest.process(src, filename); src = webpackAlias.process(src, filename); } return src; } };
Debug
Known issues
deprecatedPackage is deprecated; consider using babel-plugin-module-resolver instead.
fix
Replace with babel-plugin-module-resolver and configure Jest moduleNameMapper for aliases.
affects: >=3.0.0
gotchaDynamic require() with variables is not supported by the AST parser.
fix
Use resolve() function: require(resolve(moduleName, __filename))
affects: >=1.0.0
gotchaNon-JavaScript file requires (e.g., CSS) are not resolved; require('./style.css') fails.
fix
Manual mock the file in __mocks__ directory, or use ignore-styles.
affects: >=1.0.0
gotcharesolve.modulesDirectories only searches the package.json directory, not ancestors.
fix
Ensure modulesDirectories is relative to package.json location.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'some-module'
Webpack alias not resolved by Jest without this preprocessor.
fix
Set up jest-webpack-alias preprocessor as described in the README.
TypeError: webpackAlias.process is not a function
Incorrect import: using ESM import syntax on a CommonJS module.
fix
Use require('jest-webpack-alias') instead of import.
Upgrade
Version history
3.3.4latest on npm
Audit
Dependencies
babel-jestrequiredRequired in the typical preprocessor setup for Jest transformations
babel-registeroptionalNeeded to support ES6 import statements in the preprocessor script
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
jest-webpack-alias — npm install jest-webpack-alias · libregistry