gpt4 book ai didi

reactjs - Recharts 不适用于带有 typescript 的 React

转载 作者:行者123 更新时间:2023-12-03 14:21:41 27 4
gpt4 key购买 nike

我在处理图表库时遇到问题。
一步步

  • 创建一个空项目

  • $ 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'
    仅供引用,它不仅适用于重新图表,还适用于几个图书馆。幸运的是,我找到了 victory chart正在工作
    真是新鲜的一个新项目,刚刚加了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"
    ]
    }
    }

    最佳答案

    你没有安装 recharts,你只安装了它的类型定义。
    尝试:

    yarn install recharts

    当您安装 @types/<package-name>包,您没有安装任何可运行的代码。您只是为不提供自己类型的包安装类型定义。您仍然需要安装软件包本身。

    关于reactjs - Recharts 不适用于带有 typescript 的 React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64144212/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com