我在处理图表库时遇到问题。
一步步
- 创建一个空项目
$ npx create-react-app chart-demo --template typescript
- 添加图表
$ yarn add @types/recharts
- 运行项目
$ yarn start
它显示以下错误。
Failed to compile
./src/App.tsx
Module not found: Can't resolve 'recharts' in '\chart-demo\src'
仅供参考,它不仅适用于 recharts,而且适用于几个图书馆。幸运的是,我发现胜利图表正在运行
真的很新鲜的一个新项目,只是添加recharts
而已。
请帮我弄清楚这个问题。
Package.json
{
"name": "chart-demo",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/recharts": "^1.8.15",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"typescript": "~3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}