Cannot find module ‘react-dom/client’ from ‘node_modules/@testing-library/react/dist/pure.js’

Explanation:

When you encounter the error message “Cannot find module ‘react-dom/client’ from ‘node_modules/@testing-library/react/dist/pure.js'”, it usually means that the required module ‘react-dom/client’ cannot be found in the specified path.

Possible Solutions:

  1. Make sure that the ‘react-dom’ module is installed and properly configured in your project.
  2. Check if the module is referenced correctly in your code.
  3. Verify if the module is included in your project’s dependencies or devDependencies in the package.json file.

Example:

Let’s consider an example where you’re using create-react-app to create a React application. To fix the mentioned error:

  1. Open your terminal and navigate to the root folder of your React project.
  2. Run the following command to install the ‘react-dom’ module:
npm install react-dom
  1. Make sure that the ‘react-dom’ module is imported in the necessary file. For example, if you’re using ‘react-dom’ in your ‘App.js’ component file, add the following import statement at the top:
import React from 'react';
import ReactDOM from 'react-dom';

By following these steps, you should be able to resolve the “Cannot find module ‘react-dom/client’ from ‘node_modules/@testing-library/react/dist/pure.js'” error.

Read more

Leave a comment