Reputation: 3995
I've installer React project with Typescript:
npx create-react-app my-app --template typescript
After I run the app with npm run start
I get this error:
TypeScript error in C:/Users/neman/Desktop/projects/redux-saga-ts-boilerplate/src/index.tsx(2,22):
Could not find a declaration file for module 'react-dom'. 'C:/Users/neman/Desktop/projects/redux-saga-ts-boilerplate/node_modules/react-dom/index.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` TS7016
1 | import React from 'react';
> 2 | import ReactDOM from 'react-dom';
| ^
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
This is my package.json
{
"name": "redux-saga-ts-boilerplate",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.7",
"@types/redux-actions": "^2.6.1",
"@types/redux-logger": "^3.0.7",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"redux-actions": "^2.6.5",
"redux-logger": "^3.0.6",
"redux-saga": "^1.1.3",
"typescript": "~3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"reinstall": "rm -rf ./node_modules && npm install",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
As you can see I do have "@types/react-dom"
installed
This is my tsconfig.json
file:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}
So, what is the problem here?
Upvotes: 6
Views: 24115
Reputation: 419
this one is very common issue if not fixed still your project work but this not good way to work study every thing and solved that problem then must go .
npm install --save @types/react-dom
this command work.
Upvotes: 0
Reputation: 168
I had the same issue. Figured it out after coming across the answer to a slightly different problem. Try this:
npm install --save @types/react-dom
Hope this works for you!
Upvotes: 13