'create react app react 18 with typescript
I am trying to create react 18 app with TypeScript, I tried following this guide but I can't make it work. I can't add "types": ["react/next", "react-dom/next"] to tsconfig file. I'm getting error:
Cannot find type definition file for 'react-dom/next'.
The file is in the program because:
Entry point of type library 'react-dom/next' specified in compilerOptionsts
Cannot find type definition file for 'react-dom/next'.
The file is in the program because:
Entry point of type library 'react-dom/next' specified in compilerOptionsts
Also I can't import ReactDom from 'react-dom/client'; I'm getting this error:
Could not find a declaration file for module 'react-dom/client'. 'C:/Users/bansc/Desktop/youtube-channel/api-calls/my-app/node_modules/react-dom/client.js' implicitly has an 'any' type.
If the 'react-dom' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-dom'ts(7016)
Solution 1:[1]
Took me way too long to figure this out last week. In react-dom experimental.d.ts file:
To load the types declared here in an actual project, there are three ways. The easiest one, if your
tsconfig.jsonalready has a"types"array in the"compilerOptions"section, is to add"react-dom/experimental"to the"types"array.
So, add this to your tsconfig.json:
"types" : [
"react-dom/experimental"
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andy |
