TypeError: el.getNode 不是一个函数



我使用 rn 社区升级助手将 react-native 版本从 v0.61.0 升级到 0.65.0 .

在 package.json 文件中进行更改、运行 npm 安装、清理 android 中的构建文件夹后,构建成功,应用程序启动时会出现错误屏幕。

TypeError: el.getNode is not a function
This error is located at:
in AndroidHorizontalScrollView (at ScrollView.js:1784)
in ScrollView (at ScrollView.js:1810)
in ScrollView (at AnimatedScrollView.js:22)
in Unknown (at createAnimatedComponent.js:243)
in AnimatedComponent (at createAnimatedComponent.js:296)
in AnimatedComponentWrapper (at TabBar.js:382)
in RCTView (at View.js:32)
in View (at TabBar.js:381)
in RCTView (at View.js:32)
in View (at createAnimatedComponent.js:243)
in AnimatedComponent (at createAnimatedComponent.js:296)
in AnimatedComponentWrapper (at TabBar.js:366)
in TabBar (at MaterialTopTabBar.js:145)
in TabBarTop (at createMaterialTopTabNavigator.js:101)
in RCTView (at View.js:32)
in View (at TabView.js:190)
in TabView (at createMaterialTopTabNavigator.js:247)
in MaterialTabView (at createTabNavigator.js:197)
in NavigationView (at createNavigator.js:80)
in Navigator (at RootTabs.js:218)
in RootTabs (at SceneView.js:9)
in SceneView (at DrawerView.js:188)
in RCTView (at View.js:32)
in View (at ResourceSavingScene.js:36)

我还将反应导航从 3.x 更新到 4.x.仍然没有成功.
我无法理解这个片段指的是什么。

TypeError: el.getNode is not a function

到目前为止,我正在努力运行安卓。未在 iOS 版本上测试。

我发现我在我的应用程序中使用了 react-navigation-tabs 包。转到 node_modules> 反应导航选项卡> node_modules> 反应导航选项卡视图> src> TabBar.js.

在此 TabBar.js 文件中,您将在第 412 行找到ref={el => (this._scrollView = el && el.getNode())}

如果您选中this._scrollView被分配给第 147 行的_scrollView: ?ScrollView;,该行是从 react-native 的 ScrollView 导入的。

由于 ScrollView 不包含任何 el 或 el.getNode() 方法,捆绑器会抛出错误,显示 el.getNode() 未定义。

要解决此问题,请按照以下步骤操作:

  • 使用Import {Animated} from react-native;
  • 在第 147 行,将故障代码更改为_scrollView: Animated.ScrollView;
  • 在第 412 行,将错误代码更改为(this.scrollView = el && (el.getNode ? el.getNode() : el))
  • 清理并重建您的项目,它现在应该可以正常工作。

我能够通过点击此链接解决此错误

遇到此问题的人都可以参考此链接。

一般来说,你也可以避免调用getNode()。它也可以工作。 例如,我有:

_scrollView.current.getNode().scrollTo({x: x, y: 0, animated: true})

只是将其更改为:

_scrollView.current.scrollTo({x: x, y: 0, animated: true}).

解决了问题,错误消失了。显然,创作者不愿意纠正这一点。

看看这个 https://github.com/ptomasroos/react-native-scrollable-tab-view/issues/1138

最新更新