jest: Subpath imports are not resolved
š Bug Report
When running jest for a project that uses subpath imports, jest fails to resolve the imports.
To Reproduce
Steps to reproduce the behavior:
- add a subpath import definition to the package.json (
#loggermapping to./logger/default.jsin my repro) - import that subpath in the code used by the jest tests
- run the tests
Expected behavior
I would expect the import to be resolved just like when running the code itself, and the tests to run.
Link to repl or repo (highly encouraged)
https://github.com/googol/jest-subpath-import-repro
envinfo
System:
OS: Linux 5.10 Arch Linux
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 15.8.0 - /usr/bin/node
Yarn: 1.22.10 - /usr/bin/yarn
npm: 6.14.11 - /usr/bin/npm
npmPackages:
jest: ^26.6.3 => 26.6.3
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 21 (5 by maintainers)
Commits related to this issue
- Downgraded chalk to v4, see https://github.com/facebook/jest/issues/11100 Signed-off-by: Jaid <jaid.jsx@gmail.com> — committed to Jaid/eslint-config-jaid by Jaid 2 years ago
@stefcameron What worked for us was mapping the
eslint-universal.cjsdirectly to the import name of@eslint/eslintrc. Like this:Our error had been
and, looking at
node_modules/eslint/lib/cli-engine/cli-engine.jsline 33, we haverequire("@eslint/eslintrc");and so it was the import of@eslint/eslintrcwhich needed to be remapped. You seem to have the same problem.Good luck and please let me know if this worked for you !
I seem to be hitting this issue with ESLint 8.x (8.2.0 right now) and jest 27.3.1. I have local/custom ESLint rules, which I test with Jest and ESLintās
RuleTester, but when I try to upgrade from ESLint 7 to 8, those specific tests start to fail with this error:@mdjermanovic suggested the following
But this doesnāt help me either. I also tried mapping
'@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc.cjs',since that seems to be the default mapped import in@eslint/eslintrcās package.json:But still no fix.
Am I at least on the right path here, thinking this is my issue and I need to wait for Jest to support these āsubpath importā things (didnāt know about such mappings until now)? Or is this some other issue and I should look elsewhere?
More packages by different authors wonāt likely follow tho; thereās a reason virtually nobody has upgraded from chalk v4 to chalk v5 (see the download counts per version on npm).
Wondering if this would work for sub-dependencies too (e.g. Chalk v5 is using subpath imports as well now and more packages will follow). Seems to be quite a hassle when more packages adapt it.
Nope, waiting for
resolveto either add it or decide not to. Either way blocked byresolvesupportingexportsandimportsfieldsimportsare not yet supported unfortunately. https://github.com/facebook/jest/issues/12270#issuecomment-1034800773 is essentially latest, and I actually think that issue can be tracked instead (even though itās newer, its info is more relevant)@cborchert Bingo! Thank you. š I guess thatās the one mapping combination I didnāt try.
Following. I have the exact same issue as @stefcameron with testing custom ESLint rules (jest 27.3.1 and eslint 8.2.0)