I have following error when use react-dom/client

Compiled with problems:XERROR in src/index.tsx:2:28TS7016: 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 |
3

Best Answer


Install @types/react-dom with @latest

 npm i @types/react-dom@latest

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';

Instead of ratholing on that, I added the following statement to the tsconfig.json file to disable the ‘any’ type errors:

"noImplicitAny": false