The Wayback Machine - http://web.archive.org/web/20210329023404/https://github.com/facebook/create-react-app/issues/9891
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JJ810 opened this issue Oct 24, 2020 · 8 comments
Closed

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

JJ810 opened this issue Oct 24, 2020 · 8 comments

Comments

@JJ810
Copy link

@JJ810 JJ810 commented Oct 24, 2020

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(R) Core(TM) 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

@ehsankhfr
Copy link
Contributor

@ehsankhfr ehsankhfr commented Oct 25, 2020

This is already discussed in #9882

@BrandonGardner2
Copy link

@BrandonGardner2 BrandonGardner2 commented Nov 3, 2020

This is already discussed in #9882
@ehsankhfr

I don't think that issue is discussing the same problem. This appears to be in reference to the type declaration files, not React itself. I have the same error on a fresh CRA Typescript project today and the issue you reference already had a fix merged.

I was able to resolve this by removing node_modules and reinstalling.

@JJ810
Copy link
Author

@JJ810 JJ810 commented 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.

@BrandonGardner2
Copy link

@BrandonGardner2 BrandonGardner2 commented 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.

yea, it looked as if the @types/react failed to install in the initial creation. The dependency is created in the package.json. I just wiped node_modules in case anything else was missed.

luckily that is all that was needed haha.

@JJ810 JJ810 closed this Nov 3, 2020
@shyaboi
Copy link

@shyaboi shyaboi commented Feb 13, 2021

@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.

This worked for me, and i used the create-react-app tsx starter template.

@jowanwondergemincentro
Copy link

@jowanwondergemincentro jowanwondergemincentro commented Feb 24, 2021

Why does this work with everyone, iand not me.
I am already struggling with this for a long time.
Even after copy pasting the entire folder 'react-native-barcode-scanner-google' in the @types folder, it keeps throwing the same error. I also tried to add this line, to the tsconfig.json "noImplicitAny": false".

All without any success. Any suggestion would be greatly appreciated

@LudwigThePig
Copy link

@LudwigThePig LudwigThePig commented 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?

@jtremback
Copy link

@jtremback jtremback commented Mar 1, 2021

I'm getting this issue as well, after installing the typescript template, and then installing reactstrap.

Was able to solve it by deleting node_modules and running npm install again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants