I have an issue with handling chart libraries.
Step by step
$ npx create-react-app chart-demo --template typescript
$ yarn add @types/recharts
$ yarn start
It shows the following error.
Failed to compile
./src/App.tsx
Module not found: Can't resolve 'recharts' in '\chart-demo\src'
FYI, it's not only for recharts but for several libraries. Fortunately, I found victory chart is working
It's really fresh a new project, just added recharts
only.
Please help me to figure out this issue.
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"
]
}
}
To get started with Recharts, use a wrapper for React Native. Plunge into the gallery to take a look at the variety of options the library has to offer.
Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write charts in React applications without any pain. Main principles of Recharts are: Simply deploy with React components.
You didn't install recharts, you only installed its type definitions.
Try:
yarn install recharts
When you install a @types/<package-name>
package, you aren't installing any runnable code. You are just installing the type definitions for a package that doesn't provide it's own types. You still need to install the package itself.
It's also possible that you've installed rechart
instead of recharts
. make sure you install the correct package (recharts
).
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