Typedefs refer to v6 even when using v5

Viewed 141

I am using v5 of react-router-dom.

npm ls --depth=0 | grep 'react-router-dom'
├── @types/react-router-dom@5.3.2
├── react-router-dom@5.3.0

However, I get an error like the type definition refers to v6.

Type '{ exact: true; path: string; component: FC<{}>; }' is not assignable to type 'IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)'.
  Property 'exact' does not exist on type 'IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)'.  TS2322

    93 |           </Header>
    94 |           <ContentBody>
  > 95 |             <Route exact path="/" component={TopPage} />
       |                    ^
    96 |           </ContentBody>
    97 |         </Content>
    98 |       </Container>

I would like to know how to avoid this without updating to v6.

1 Answers

Had the same problem recently, in my case i ran: npm list react-router to check where it was installed. Turned out it was installed in an other dependency using storybook dependent on v6.1.1. I fixed the problem by installing a version of react router myself: npm install react-router@5.2.0 --save

Related