[Bug]: package `exports` is not supported for extension-less directory mappings
Version
28.1.1
Steps to reproduce
- Install a package that has
exportsfield, in form of
"exports": {
"./prefix/": "./other-directory/" // Not `./other-directory/some-file.js`
}
- Run a test that imports
./prefix/something(not./prefix/something.js) - You should see module not found errors raised by jest.
Expected behavior
It should resolve modules based on the mapping, even if the mapping value is a directory.
Actual behavior
If the mapping is to a directory, moduleFileExtensions is ignored in module resolution, and the module resolution fails, if extension is not specified.
At least Webpack and Vite support extension-less directory-to-directory mapping in exports field.
Additional context
In defaultResolver, getPathInModule correctly takes exports into account and returns the mapped path.
https://github.com/facebook/jest/blob/48f3d81385e1324976b7c5b3dda5d4bd9cf0bb17/packages/jest-resolve/src/defaultResolver.ts#L112
But the returned path (pathToResolve) would not be equal to path. Which means resolveSync would not be called on the resolved path:
That check must have been there for a reason, as the comment in the code explains, but it should be adjusted to accommodate for pathToResolve being different from path due to exports.
Environment
System:
OS: macOS 12.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.3/bin/yarn
npm: 6.14.14 - ~/.nvm/versions/node/v14.15.3/bin/npm