This is my first time using typescript with React and I'm have a tremendous amount of trouble with the typescript Module has no exported member .ts(2305)
error. Here are 2 examples of this happening:
import { BrowserRouter, Routes, Route } from 'react-router-dom';
Error:
'"react-router-dom"' has no exported member named 'Routes'. Did you mean 'Route'?ts(2724)
And here
import { useNavigate } from 'react-router';
Error:
Module '"react-router"' has no exported member 'useNavigate'.ts(2305)
Last example:
import { MaterialCommunityIcons } from 'react-native-vector-icons';
Error:
Module '"react-native-vector-icons"' has no exported member 'MaterialCommunityIcons'.ts(2305)
Here is my package.json file if that helps:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.3.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/history": "2.0.45",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router": "3",
"@types/react-router-dom": "^5.1.8",
"community": "^0.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"history": "^5.0.1",
"icons": "^1.0.0",
"material": "^0.4.3",
"prettier": "^2.3.2",
"react": "^17.0.1",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.1",
"react-native-vector-icons": "^8.1.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"react-vector-icons": "^0.0.1",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
What can I do to fix this issue when it comes up? I'm not exactly asking about these 3 particular issues, but how to solve the Module has no exported member .ts(2305)
error because it seems to come up often.
What I have read a couple times and have tried to do is install the type definitions (I think?) like this:
yarn add @types/react-router-dom
and yarn add @types/react-router
and finally yarn add @types/react-native-vector-icons
and trying simply yarn install
but this has never solved the problem.
Restarting the typescript server worked for me:
ctrl+shift+p
> Typescript: Restart TS server
(click enter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With