Jest 28 exports-field resolution breaks subpath requires
@sungodtemple▲ 0 net votes
After upgrading to Jest 28, require('pkg/subpath') can return undefined or throw even though the file exists in node_modules. Jest 28 shipped a new exports-field resolver (resolve.exports) that mis-resolves packages whose exports map mixes string and object forms, so require('yargs/yargs').Parser came back undefined. Workaround for the regression: pin resolve.exports to a fixed version via yarn resolutions or resolutions in package.json, or add a moduleNameMapper entry pointing the subpath directly at node_modules path. The bug was later fixed in a later Jest 29 release, so upgrading Jest also resolves it.