{"id":20157,"library":"jest-webpack-alias","title":"jest-webpack-alias","description":"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.","status":"deprecated","version":"3.3.4","language":"javascript","source_language":"en","source_url":"https://github.com/mwolson/jest-webpack-alias","tags":["javascript","jest","webpack","require","resolve","alias"],"install":[{"cmd":"npm install jest-webpack-alias","lang":"bash","label":"npm"},{"cmd":"yarn add jest-webpack-alias","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest-webpack-alias","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required in the typical preprocessor setup for Jest transformations","package":"babel-jest","optional":false},{"reason":"Needed to support ES6 import statements in the preprocessor script","package":"babel-register","optional":true}],"imports":[{"note":"CommonJS module; only works with require, not ESM default import.","wrong":"import webpackAlias from 'jest-webpack-alias'","symbol":"jest-webpack-alias","correct":"require('jest-webpack-alias')"},{"note":"Exported member for manual resolution of dynamic requires.","wrong":"const resolve = require('jest-webpack-alias').resolve","symbol":"resolve","correct":"const { resolve } = require('jest-webpack-alias')"}],"quickstart":{"code":"// __tests__/preprocessor.js\nvar babelJest = require('babel-jest');\nrequire('babel-register');\nvar webpackAlias = require('jest-webpack-alias');\n\nmodule.exports = {\n  process: function(src, filename) {\n    if (filename.indexOf('node_modules') === -1) {\n      src = babelJest.process(src, filename);\n      src = webpackAlias.process(src, filename);\n    }\n    return src;\n  }\n};","lang":"javascript","description":"Shows the typical setup for a Jest preprocessor that applies babel-jest and webpack alias resolution."},"warnings":[{"fix":"Replace with babel-plugin-module-resolver and configure Jest moduleNameMapper for aliases.","message":"Package is deprecated; consider using babel-plugin-module-resolver instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Use resolve() function: require(resolve(moduleName, __filename))","message":"Dynamic require() with variables is not supported by the AST parser.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manual mock the file in __mocks__ directory, or use ignore-styles.","message":"Non-JavaScript file requires (e.g., CSS) are not resolved; require('./style.css') fails.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure modulesDirectories is relative to package.json location.","message":"resolve.modulesDirectories only searches the package.json directory, not ancestors.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Set up jest-webpack-alias preprocessor as described in the README.","cause":"Webpack alias not resolved by Jest without this preprocessor.","error":"Cannot find module 'some-module'"},{"fix":"Use require('jest-webpack-alias') instead of import.","cause":"Incorrect import: using ESM import syntax on a CommonJS module.","error":"TypeError: webpackAlias.process is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}