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

Viewed 7519

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?

2 Answers

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

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

Related