【TypeScript】【React】Could not find a declaration file for module ‘react’
This is a note for error handling.
import React from 'react';
I got the error in all directories of my project.
Could not find a declaration file for module ‘react’. ‘/Users/username/projects/project-name/node_modules/react/index.js’ implicitly has an ‘any’ type.
If the ‘react’ package actually exposes this module, consider sending a pull request to amend......
When I googled for this error handling, it is found that:
It said that above line should be added. However, it did not work for me. On the contrary, “noImplicitAny” is not being in my tsconfig.json.
Since react is not written in typescript and the type is not provided in the original package, it was necessary to install the type separately.
yarn add -D @types/react
npm install -D @types/react
This worked for me.
If this note would be helpful for you, it would be happy for me as well.