12

When running yarn test in package.json which is

CI=true react-app-rewired test --coverage

I got following error

Test suite failed to run

    Cannot find module 'react' from 'pure.js'

    However, Jest was able to find:
        './pure.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (../../node_modules/@testing-library/react/dist/pure.js:28:37)

Not sure why getting react from pure.js, any idea?

3
  • Have you checked that React is installed? Try installing with npm i react and running again. If it works, react wasn't installed properly in the first place. Commented Mar 11, 2020 at 12:35
  • 1
    @AJarofClay, I figured out that the project has 2 package.jsons top level dir and inner level dir . So need to stick to inner level dir to do dev Commented Mar 11, 2020 at 13:14
  • Does this answer your question? Cannot find module 'react-dom/client' from 'node_modules/@testing-library/react/dist/pure.js' Commented Feb 24, 2023 at 8:01

3 Answers 3

13

I was also facing the same issue, then I installed "react-test-renderer": "^16.13.1" and the issue is resolved. So you can try this also just installed this dependency by command npm install react-test-renderer --save.

As you can see in the below image:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

Jest is unable to find 'react' because it is either not installed or the closest package.json does not have react as a dependency (if it's a monorepo).

Comments

0

It's related to Version of @testing-library/react not being compatible with your react version

as mentioned here

I think it's because your using the newer version of @testing-library/react , just try installing version 12.1.2 (or 12.x)

[quote edited by me]

And as Kalm mentioned here too

if it's a mono repo project, you have to take care of every package.json file.

in my case(in a monorepo project), someone has installed a higher version of @testing-library/react which will not work with my current react version, so the solution was to trace every package.json and check what version of @testing-library/react I was using, then make sure it's using a lower version

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.