Nx jest resolver might resolve the same file as different modules #20865
Labels
outdated
scope: testing tools
Issues related to Cypress / Jest / Playwright / Vitest support in Nx
type: bug
Current Behavior
Given the following conditions:
tsconfig.spec.json
at the root of the workspace"@demo/stuff/*": ["apps/demo/stuff/*"]
) + a barrel export inindex.ts
then importing the same symbol from the
@demo/stuff
and@demo/stuff/something
will produce different symbols:This can break many things (e.g. dependency injection, variables holding global variables / counters etc...)
It seems that the problem comes partially from Nx jest resolver:
nx/packages/jest/plugins/resolver.ts
Line 76 in 2f9060e
test-setup.ts
), therootDir
isundefined
tsconfig.spec.json
does exist in the workspace root,getCompilerSetup()
works instead of crashing and resolves the configuration from the root config which resolves TSrootDir
to.
instead of the absolute path to the library.Suggested solutions
A. While I still don't understand why
rootDir
isundefined
, throwing an error ingetCompilerSetup()
ifrootDir
is undefined is a better option than mistakenly usingtsconfig.spec.json
from the workspace root as it solves this issue.B. We could improve the heuristics of finding the "right" tsconfig.
Expected Behavior
Modules should be resolved consistently no matter what the configuration is.
GitHub Repo
https://github.com/yjaaidi/experiments/tree/repro/nx-jest-resolver
Steps to Reproduce
nx test demo
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: