3

I'm currently experiencing this error and I'm not really sure how to fix it. I've been trying to merge a project with components stored in bit.dev.

import React from 'react';
import { createRoot } from 'react-dom/client'; // Cannot find module 'react-dom/client' or its corresponding type declarations.
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom';

import 'bootstrap/dist/css/bootstrap.min.css';

const rootElement = document.getElementById('root');
if (!rootElement) throw new Error('Failed to find the root element');
const root = createRoot(rootElement);
root.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>
);

Here is the code. Thanks for your help!

1

3 Answers 3

4

For anyone that might experience the same problem, the version of react bit.dev is using and the version the actual app is using are different. All I had to do was change the way the app was rendered (in this case react v17).

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom';

import 'bootstrap/dist/css/bootstrap.min.css';

ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);
Sign up to request clarification or add additional context in comments.

Comments

4

After running npm install react react-dom or yarn add react react-dom as instructed here, you should then run

npm install -D @types/react-dom

or

yarn add -D @types/react-dom

This will add react-dom/client type declarations to your project and will remove the error you pointed at on line 2 of your code.

1 Comment

Of course, they were already installed. Yet it continues to show that error for react-dom/client.
-2

Try

import * as ReactDOM from 'react-dom/client';

Then ReactDOM.createRoot

1 Comment

It gives the same error/warning.

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.