3

error

node_modules/@types/react-router-dom/index.d.ts:13:10 - error TS2305: Module '"react-router"' has no exported member 'match'.
node_modules/@types/react-router-dom/index.d.ts:19:5 - error TS2305: Module '"react-router"' has no exported member 'PromptProps'.
node_modules/@types/react-router-dom/index.d.ts:20:5 - error TS2305: Module '"react-router"' has no exported member 'Prompt'.
node_modules/@types/react-router-dom/index.d.ts:23:5 - error TS2305: Module '"react-router"' has no exported member 'RedirectProps'.
node_modules/@types/react-router-dom/index.d.ts:24:5 - error TS2305: Module '"react-router"' has no exported member 'Redirect'.
node_modules/@types/react-router-dom/index.d.ts:25:5 - error TS2305: Module '"react-router"' has no exported member 'RouteChildrenProps'.
node_modules/@types/react-router-dom/index.d.ts:26:5 - error TS2305: Module '"react-router"' has no exported member 'RouteComponentProps'.
node_modules/@types/react-router-dom/index.d.ts:31:5 - error TS2305: Module '"react-router"' has no exported member 'StaticRouterProps'.
node_modules/@types/react-router-dom/index.d.ts:32:5 - error TS2305: Module '"react-router"' has no exported member 'StaticRouter
node_modules/@types/react-router-dom/index.d.ts:33:5 - error TS2305: Module '"react-router"' has no exported member 'SwitchProps'.
node_modules/@types/react-router-dom/index.d.ts:34:5 - error TS2305: Module '"react-router"' has no exported member 'Switch'.
node_modules/@types/react-router-dom/index.d.ts:35:5 - error TS2305: Module '"react-router"' has no exported member 'match'.
... same errors but different members

node_modules/@types/react-router/index.d.ts:189:53 - error TS2694: Namespace '"C:/Users/user/Desktop/app/frontend/node_modules/history/index"' has no exported member 'LocationState'.
189 export function useHistory<HistoryLocationState = H.LocationState>(): H.History<HistoryLocationState>;
node_modules/@types/react-router/index.d.ts:189:71 - error TS2315: Type 'History' is not generic.
189 export function useHistory<HistoryLocationState = H.LocationState>(): H.History<HistoryLocationState>;                     
node_modules/@types/react-router/index.d.ts:191:35 - error TS2694: Namespace '"C:/Users/user/Desktop/app/frontend/node_modules/history/index"' has no exported member 'LocationState'.
191 export function useLocation<S = H.LocationState>(): H.Location<S>;                                   
node_modules/@types/react-router/index.d.ts:191:53 - error TS2315: Type 'Location' is not generic.
191 export function useLocation<S = H.LocationState>(): H.Location<S>;
... again more errors

package.json

{
  "name": "frontend",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@reduxjs/toolkit": "^1.7.0",
    "@types/react-redux": "^7.1.20",
    "@types/react-router-dom": "^5.3.2",
    "axios": "^0.24.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.6",
    "react-router-dom": "^6.1.0"
  },
  "devDependencies": {
    "@types/react": "^17.0.33",
    "@types/react-dom": "^17.0.10",
    "@vitejs/plugin-react": "^1.0.7",
    "typescript": "^4.4.4",
    "vite": "^2.7.0"
  }
}

Whenever I try to build, it shows me all of these errors which i have never encountered before so no idea why this is happening..., the first part has to do with ts so that's fixable but the 2nd part doesn't make sense, any help is appreciated!

2
  • Looks like you've accidentally upgraded to react-router-dom v6.... none of those items being complained about exist in v6, they were removed. Either revert back to v5 or follow the upgrade from v5 guide. Commented Dec 13, 2021 at 17:52
  • The same issue i upgraded to v6 - but types non exist Commented Jan 11, 2022 at 14:50

3 Answers 3

3

I have the same issue. My environment works when I am in develop mode, but I get some react-router-dom errors when I start the build via vite.

It looks like that @types/react-router-dom is not available for react-router v6, yet. Currently, https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router-dom/index.d.ts shows Type definitions for react-router-dom 5.3.

So the options are to downgrade to react-router v5, or wait until types for v6 are available.

Sign up to request clarification or add additional context in comments.

Comments

2

Maybe you can try add "skipLibCheck": true to tsconfig.json.

{
  "compilerOptions": {
    // ...
    "skipLibCheck": true
  }
}

Comments

0

I had the same issue, so I updated my typescript and its work :)

The bundler module resolution is a new feature only work on Typescript 5.x. Try to update latest typescript with the following command.

npm update typescript -g 
 or
npm install typescript@latest -g

Check: https://github.com/vitejs/vite/issues/13129

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.