jest-webpack-resolver
raw JSON → 0.3.0 verified Sat Apr 25 auth: no javascript maintenance
Jest plugin that replaces Jest's default module resolution with Webpack's resolver using the project's webpack.config.js. Version 0.3.0 is the latest stable release; the package is no longer actively maintained. It supports Jest >=20 and resolves Webpack features like aliases, extensions, modules, mainFields, and plugins. Unlike manual mocking, it allows Jest to mirror Webpack's resolve behavior automatically.
Common errors
error Cannot find module 'jest-webpack-resolver' ↓
cause Package not installed or missing from devDependencies
fix
npm install jest-webpack-resolver --save-dev
error Configuration error: unknown option 'jestWebpackResolver' ↓
cause jestWebpackResolver option placed under incorrect key in Jest config
fix
Place jestWebpackResolver at root level of package.json or jest.config
error Webpack Resolver using: ./webpack.config.js (not found) ↓
cause webpackConfig path is incorrect or file does not exist
fix
Ensure webpackConfig points to an existing webpack configuration file
Warnings
breaking jest >=20.0.0 required; older versions lack resolver option ↓
fix Upgrade Jest to version 20 or later
gotcha Webpack config must export an object or a function returning an object ↓
fix Ensure webpack.config.js returns a valid webpack configuration
deprecated Package is no longer actively maintained; consider alternatives like jest-webpack-resolution or custom resolver ↓
fix Migrate to actively maintained alternatives
gotcha The resolver only supports a single webpack config; multiple configs not supported ↓
fix Merge configs or use a custom resolver
Install
npm install jest-webpack-resolver yarn add jest-webpack-resolver pnpm add jest-webpack-resolver Imports
- default wrong
const resolver = require('jest-webpack-resolver');correctno import needed; set resolver in Jest config
Quickstart
// package.json
{
"jest": {
"resolver": "jest-webpack-resolver",
"jestWebpackResolver": {
"webpackConfig": "./webpack.config.js",
"silent": true
}
}
}
// webpack.config.js
module.exports = {
resolve: {
alias: {
Components: './src/components'
},
extensions: ['.js', '.jsx']
}
};
// Then run: npx jest