Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find a declaration file for module 'react-dom/client'

I have following error when use react-dom/client

Compiled with problems:X

ERROR in src/index.tsx:2:28

TS7016: Could not find a declaration file for module 'react-dom/client'. 'C:/Users/Mohamad/Desktop/HIS/Administration/Administration/Administration/Administration.Endpoints.WebUI/ClientApp/node_modules/react-dom/client.js' implicitly has an 'any' type.
  Try `npm install @types/react-dom` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-dom/client';`
    1 | import * as React from 'react';
  > 2 | import { createRoot } from 'react-dom/client';
      |                            ^^^^^^^^^^^^^^^^^^
    3 | import App from './App';
    4 |
    5 |
like image 202
Mohammad Ramezani Avatar asked Sep 09 '25 18:09

Mohammad Ramezani


2 Answers

Install @types/react-dom with @latest

 npm i @types/react-dom@latest
like image 108
Antechamber Avatar answered Sep 12 '25 08:09

Antechamber


Error message actually states the solution:

You need to install the package or define in .d.ts file

However for my case, I had to do both of them to resolve the issue.

Install the package:

npm install @types/react-dom

Define in .d.ts

declare module 'react-dom/client';
like image 32
Sabri Özgür Avatar answered Sep 12 '25 08:09

Sabri Özgür