不变违规:requireNativeComponent:在 UIManager 中找不到“RNSVGSvgViewAndroid”

per*_*n66 19 android typescript react-native expo-go

我对标题中提到的错误感到头疼。\n我正在使用react-native-gifted-charts(https://www.npmjs.com/package/react-native-gifted-charts/v/1.0.3)\n图表在 ios 中完美运行,但在 Android 中它不断崩溃并抛出“Invariant Violation: requireNativeComponent: 在 UIManager 中找不到“RNSVGSvgViewAndroid”。”\n首先我认为这是我的代码的问题,因为它之前适用于 Android ,但即使我反转代码,错误仍然存​​在。\n我正在使用yarn作为包管理器和Expo托管工作流程。\n依赖项如下。

\n
"react-native": "0.70.5",\n"react-native-gifted-charts": "^1.2.42",\n"react-native-linear-gradient": "2.6.2",\n"react-native-svg": "12.1.0",\n\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x96\xa0我尝试过的事情

\n
    \n
  1. 我删除了节点模块并再次运行yarn \xe2\x86\x90 不起作用
  2. \n
  3. 我更改了react-native-svg的版本,正如我在下面的文章中读到的那样,有时这种错误是由于版本不匹配而发生的。\xe2\x86\x90没有\n工作\n https://github 。 com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/263
  4. \n
  5. 我删除了react-native-gifted-chartsreact-native-linear-gradientreact-native-svg并再次添加了yarn以查看它是否解决了问题。\xe2\x86\x90 不起作用
  6. \n
  7. 最后,为了确认我的代码不是问题,我删除了所有代码并制作了一个简单的 barChart 示例来查看它是否有效(下面的示例代码) \xe2\x86\x90 没有工作
  8. \n
\n
import React, { useState } from "react";\nimport { View, StyleSheet, Text, TouchableOpacity, ScrollView } from "react-native";\nimport type { NativeStackScreenProps } from "@react-navigation/native-stack";\nimport { MainStackParamList } from "../types/navigation";\nimport dayjs from "dayjs";\nimport { BarChart, LineChart, PieChart } from "react-native-gifted-charts";\nimport { useSelector } from "react-redux";\nimport { RootState } from "../store";\n\nexport const StatisticsScreen: React.FC<Props> = () => {\n  const data=[ {value:50}, {value:80}, {value:90}, {value:70} ]\n  return (\n    <BarChart\n      data={data}\n    />\n  );\n};\n
Run Code Online (Sandbox Code Playgroud)\n

PS我还运行了yarncache clean希望它是缓存但没有帮助......

\n

小智 50

我在尝试使用时也遇到了同样的问题react-native-heroicons,需要我安装react-native-svg,但是当我运行时npx expo install react-native-svg,它起作用了。


小智 15

我在使用时遇到错误"react-native-svg": "13.6.0",降级以"react-native-svg": "13.4.0"解决问题。

那么也许您可以尝试升级到该13.4.0版本?


小智 7

Expo 适用于 13.4.0 版本react-native-svg,但react-native-gifted-charts需要 13.6.0。因此,我安装react-native-svgexpo install覆盖嵌套依赖项以使用 13.4.0 版本,还通过添加

  "resolutions": {
    "react-native-svg": "13.4.0"
  } 
Run Code Online (Sandbox Code Playgroud)

到我的 package.json。解决了我的问题


小智 -1

SVG渲染需要这个模块

npm install react-native-svg-transformer --save 
Run Code Online (Sandbox Code Playgroud)