【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:

“noImplicitAny”: false,

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.

Solution

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

or

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.

--

--

--

80% is the creation, the rest is depression. Frontend developer and data scientist, designer. Looking for Physics Ph.D Twitter: @_t_i_show

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

“Hello World” in React

Smart Mat-Table Part 1 : Reusable & Customizable

Adding multiple components to your Ionic application

Start ES6 today to get you settled

Nuxt.js (v1), Firestore & SSR 🔥

React vs Vue.js

Time is money: Performance improvements in admin ui

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TiShow

TiShow

80% is the creation, the rest is depression. Frontend developer and data scientist, designer. Looking for Physics Ph.D Twitter: @_t_i_show

More from Medium

React Router DOM v6 — Part — I

What Is React JS & Why To Use It?

Using React 18 in Component Testing — Cypress

Running asynchronous redux-saga tests