Could not find a declaration file for module in React Js

Viewed 10974

VB CODE code Hi everyone! I am writing a single application using REACT and when I was trying to use import { BrowserRouter, Route, Link } from "react-router-dom";

I am getting the following error:

Could not find a declaration file for module 'react-router-dom'. 'c:/Users/paula/first-app/node_modules/react-router-dom/index.js' implicitly has an 'any' type. Try npm install @types/react-router-dom if it exists or add a new declaration (.d.ts) file containing declare module 'react-router-dom';ts(7016)

I did install "npm install react-router-dom", but can't figure out what the problem is.

2 Answers

Like the error message says, you also need to install the types of react-router-dom:

npm install @types/react-router-dom -D

or

yarn add @types/react-router-dom -D
Instead of using **<BrowserRouter>** use 
    <Router>
         <Switch>
                 <Route path="/" component={componentName}/>
          </Switch>
    </Router>

avoid div inside router

Related