Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest tests fail when TypeScrip tsconfig baseUrl set to '.' and the project is nested in a src directory. moduleNameMapper error. #7833

Closed
pbeshai opened this issue Oct 16, 2019 · 0 comments

Comments

@pbeshai
Copy link

pbeshai commented Oct 16, 2019

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:)

  1. npx create-react-app my-app --typescript
  2. Add baseUrl: "." to tsconfig.json
  3. 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.

@pbeshai pbeshai closed this as completed Oct 16, 2019
@lock lock bot locked and limited conversation to collaborators Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant