1
votes

I'm trying to import React from 'react' and getting an error..

The setup I'm using was created with the standard npx create-react-app.

The error I'm seeing is from VS Code.

import React from 'react';

Could not find a declaration file for module 'react'. '/home/darryl/dev/learn-react/node_modules/react/index.js' implicitly has an 'any' type. Try npm install @types/react if it exists or add a new declaration (.d.ts) file containing `declare m

I'd expect to not receive this error and for my app to load in the browser.

I haven't tried the suggest fix yet 'npm install @types/react' as I should not be receiving this error anyway and I was hoping to gain further understanding of why I am seeing this before making changes.

Thanks

3

3 Answers

2
votes

Try npm install --save react .

2
votes

Running the suggested fix 'npm install @types/react' seems to fix the issue. But this seems to be an issue with the create-react-app installer then?

0
votes

Is react well listed in "dependencies" in your package.json ?

Have you try to import it with require (Vanilla Style instead of ES6)?