Importing the graph kit in React Native results in error 500

徘徊边缘 提交于 2019-12-14 02:14:29

问题


I am using the latest version of Expo. I have created a project by expo init my_project and added the React Native Chart Kit. Here is the package.json:

    {
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "^35.0.0",
    "react": "16.8.3",
    "react-dom": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
    "react-native-chart-kit": "^3.6.1",
    "react-native-web": "^0.11.7"
  },
  "devDependencies": {
    "babel-preset-expo": "^7.0.0"
  },
  "private": true
}

When I import the following it gives me the error: "The development server returned response error code: 500":

  import {
  LineChart,
  BarChart,
  PieChart,
  ProgressChart,
  ContributionGraph,
  StackedBarChart
} from "react-native-chart-kit";

Why this error happens even though this module is accessible through the Expo as it stated in this [page][2]?

[2]: https://forums.expo.io/t/any-graph-library/1674/7


回答1:


Most cases this error is related to your node_modules, try the following:

  1. Stop your Expo application server
  2. Delete your node_modules directory and package-lock.json
  3. Run npm install or yarn install
  4. Run npm install --save react-native-svg
  5. Start your application by running expo start -c

Hope this helps!




回答2:


To use react-native-chart-kit, you also have to install react-native-svg. So, just install it through npm and hopefully it will work.

$ npm i react-native-svg react-native-chart-kit

You can try my project on this repo: click here. Enjoy 👍



来源:https://stackoverflow.com/questions/58209929/importing-the-graph-kit-in-react-native-results-in-error-500

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!