typescript: Cannot find module 'react'
As on version 2.4.* the responsible config entry of this error (in most of the cases) is:
"compilerOptions": {
...
"moduleResolution": "node" <---------- this entry
...
}
For resolving the typescript "Cannot find module 'react'", which comes from eslint rules,
You need to install @types/react
:
$ npm i -D @types/react
or
$ yarn add -D @types/react
And in your ".eslintrc" file add in extends
array the react plugin:
...
extends: [
'plugin:react/recommended',
...
],
if you're not using typescript 2.1, you should upgrade to it. it looks like you're using a 2.x version from the @types you have there.
here is a working tsconfig.json
file that i'm using right now:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"noResolve": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"allowJs": true,
"jsx": "react"
},
"exclude": [
"./node_modules/**/*"
]
}
it's been a couple days since i resolved the same issue you were having, but i think the key here is the "moduleResolution": "node"
and "allowJs": true
.
I had the same issue. You just need to install @types:
npm i -D @types/react