-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Description
Describe the bug
When a project is nested somewhere in a directory named src, and the baseUrl in tsconfig.json is set to ".", all tests will fail with the following error:
FAIL src/App.test.tsx
● Test suite failed to run
Configuration error:
Could not locate module /Users/pbeshai/Workspace/bug-report/src/nested-src-bug-ts/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault mapped as:
/Users/pbeshai/Workspace/bug-report/src/nested-src-bug-ts/src/nested-src-bug-ts/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/src\/(.*)$/": "/Users/pbeshai/Workspace/bug-report/src/nested-src-bug-ts/src/$1"
},
"resolver": null
}
After some investigation, I believe this is because the moduleNameMapper is not prefixed with ^ and so it matches the src earlier in the path.
Steps to reproduce
(Write your steps here:)
- npx create-react-app my-app --typescript
- Add
baseUrl: "."to tsconfig.json - yarn test
Reproducible demo
https://github.com/pbeshai/cra-nested-src-bug-ts
Proposed Solution
In #7755 baseUrl was allowed to be set to .. If we modify ... I now see this is already fixed in #7818 and #7822.
I'll post and close this just in case someone else is stumbling on this problem and couldn't find any results.