jest-pnp-resolver
raw JSON → 1.2.3 verified Sat Apr 25 auth: no javascript
A plug'n'play (PnP) resolver for Jest that enables resolution of dependencies in Yarn PnP environments. Current stable version is 1.2.3, with infrequent releases. Key differentiators: it is the official resolver for Yarn PnP with Jest, and as of Jest 24.4.0+, it is integrated by default, but manual setup may still be needed for custom configurations or older versions. Alternatives include using the default Jest resolver with node_modules or other custom resolvers for different package managers.
Common errors
error Cannot find module 'jest-pnp-resolver' ↓
cause Package not installed or not in node_modules.
fix
Run yarn add -D jest-pnp-resolver
error Could not locate module … mapped as … ↓
cause moduleNameMapper is not compatible with PnP resolution when mapping to node_modules paths.
fix
Update moduleNameMapper to map to actual file paths within PnP virtual file system.
error Jest encountered an unexpected token … ↓
cause Usually due to missing Babel transpilation; PnP resolver alone does not handle syntax transforms.
fix
Add appropriate transform configuration in jest.config.js (e.g., babel-jest).
Warnings
deprecated As of Jest 24.4.0+, the default resolver already supports PnP, making jest-pnp-resolver unnecessary for most users. ↓
fix Remove resolver configuration from jest.config.js to use the built-in PnP support.
breaking This resolver only works with Yarn PnP (plug'n'play) installations. It will fail if used with a node_modules-based setup. ↓
fix Ensure your project uses Yarn PnP (i.e., has .pnp.js or .pnp.cjs file).
gotcha Using require.resolve('jest-pnp-resolver') in jest.config.js may resolve to the wrong path if the package is not installed. ↓
fix Install jest-pnp-resolver as a devDependency: yarn add -D jest-pnp-resolver
gotcha The resolver does not support custom module directories or moduleNameMapper patterns that rely on node_modules. ↓
fix Use transform or other Jest configuration to adjust module resolution.
Install
npm install jest-pnp-resolver yarn add jest-pnp-resolver pnpm add jest-pnp-resolver Imports
- jest-pnp-resolver wrong
import { jest-pnp-resolver } from 'jest-pnp-resolver'correctimport 'jest-pnp-resolver' - require.resolve wrong
resolver: 'jest-pnp-resolver'correctresolver: require.resolve('jest-pnp-resolver') - module.exports wrong
module.exports = { resolver: 'jest-pnp-resolver' }correctmodule.exports = { resolver: require.resolve('jest-pnp-resolver') }
Quickstart
// jest.config.js
module.exports = {
resolver: require.resolve('jest-pnp-resolver')
};