question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Couldn't find a declaration file for module 'react'

See original GitHub issue

Describe the bug

I created a typescript template create-react-app by running npx create-react-app --template typescript and tried to import useEffect and useState. After I import and save file, I got an error: Could not find a declaration file for module ‘react’

Did you try recovering your dependencies?

6.14.6

Environment

current version of create-react-app: 4.0.0 running from /Users/healer/.npm/_npx/25783/lib/node_modules/create-react-app

System: OS: macOS High Sierra 10.13.6 CPU: (6) x64 Intel® Core™ i5-8400 CPU @ 2.80GHz Binaries: Node: 10.22.1 - ~/.nvm/versions/node/v10.22.1/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.6 - ~/.nvm/versions/node/v10.22.1/bin/npm Browsers: Chrome: 86.0.4240.111 Edge: 86.0.622.51 Firefox: 81.0.2 Safari: 13.0.5 npmPackages: react: ^17.0.1 => 17.0.1 react-dom: ^17.0.1 => 17.0.1 react-scripts: 4.0.0 => 4.0.0 npmGlobalPackages: create-react-app: Not Found

Steps to reproduce

  1. run npx create-react-app --template typescript
  2. open App.tsx and import useEffect and/or useState import React, { useEffect, useState } from 'react'
  3. save file and refresh

Actual behavior

I got error and couldn’t run the project.

Screen Shot 2020-10-24 at 4 01 35 PM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

54reactions
JJ810commented, Nov 3, 2020

@BrandonGardner2, you should run

npm install @types/react

to fix this issue. But I couldn’t find where to add this package in this repo.

20reactions
LudwigThePigcommented, Feb 28, 2021

I ran npx create-react-app my-app --template typescript as described in the create-react-app docs and saw the same error.

Why is this happening for clean runs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module ''react-materialize ...
I had a similar error but for me it was react-router . Solved it by installing types for it. npm install --save @types/react-router....
Read more >
Could not find declaration file for module 'react' | bobbyhadz
The error "could not find declaration file for module 'react'" occurs when TypeScript cannot find the type declaration for a react-related module.
Read more >
【TypeScript】【React】Could not find a declaration file for ...
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/ ...
Read more >
How to use a module when it could not find a declaration file ...
Coding example for the question How to use a module when it could not find a declaration file-Reactjs.
Read more >
could not find a declaration file for module - Code Grepper
1. yarn add @types/react-router-dom -D ; 2. ​ ; 3. Instead of using **<BrowserRouter>** use ; 4. ​ ; 5. <Router>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found