Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 586
kenpeter Avatar asked Mar 10 '20 12:03

kenpeter


People also ask

Can not find module in react?

To solve the "Cannot find module react or its corresponding type declarations" error, install the module and its type definitions by running the commands npm install react and npm i --save-dev @types/react . Copied! Now you should be able to import the react library with the following line of code.

Can not find module react Dom client?

To solve the error "Module not found: Error: Can't resolve 'react-dom'", make sure to install the react-dom package by opening your terminal in your project's root directory and running the command npm install react-dom react and restart your development server.

Can't find module in path react?

To solve the error "Cannot find module 'react/jsx-runtime' or its corresponding type declarations", make sure to install the typings for react running the command npm install --save-dev @types/react@latest @types/react-dom@latest and restart your dev server.

Could not find a declaration file for module react?

The error "could not find declaration file for module 'react'" occurs when TypeScript cannot find the type declaration for a react-related module. To solve the error install the types for the module by running the command from the error message, e.g. npm install -D @types/react .


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

like image 102
Shubham Verma Avatar answered Oct 16 '22 16:10

Shubham Verma


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

like image 25
kalm42 Avatar answered Oct 16 '22 16:10

kalm42