【发布时间】:2021-12-07 06:33:44
【问题描述】:
这是我第一次在 React 中使用 typescript,我遇到了很多关于 typescript Module has no exported member .ts(2305) 错误的麻烦。以下是发生这种情况的 2 个示例:
import { BrowserRouter, Routes, Route } from 'react-router-dom';
错误:
'"react-router-dom"' has no exported member named 'Routes'. Did you mean 'Route'?ts(2724)
这里
import { useNavigate } from 'react-router';
错误:
Module '"react-router"' has no exported member 'useNavigate'.ts(2305)
最后一个例子:
import { MaterialCommunityIcons } from 'react-native-vector-icons';
错误:
Module '"react-native-vector-icons"' has no exported member 'MaterialCommunityIcons'.ts(2305)
如果有帮助,这是我的 package.json 文件:
{
"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"
},
当它出现时,我可以做些什么来解决这个问题?我并不是在问这 3 个特定问题,而是在问如何解决 Module has no exported member .ts(2305) 错误,因为它似乎经常出现。
我读过几次并尝试做的是像这样安装类型定义(我认为?):
yarn add @types/react-router-dom 和 yarn add @types/react-router 最后是 yarn add @types/react-native-vector-icons 并尝试简单地 yarn install 但这从未解决问题。
【问题讨论】:
标签: reactjs typescript