繁体   English   中英

TypeError: undefined is not an object(评估'_reactNative.Animated.Text.propTypes.style')

[英]TypeError: undefined is not an object (evaluating '_reactNative.Animated.Text.propTypes.style')

将 React Native 升级到0.62.2并安装react-native-material-dropdown `库后,项目出现此错误:

在此处输入图像描述

我解决了这个问题,

  • 评论itemTextStyle: Text.propTypes.style in
    ..\node_modules\react-native-material-dropdown\src\components\dropdown文件。

  • 并删除Animated中的Animated.Text.propTypes.style

    词缀/索引

    助手/索引

    标签/索引

    react-native-material-textfield

  • 并添加了import { Animated, Text} from 'react-native'; 在上述三个文件中的每一个中。

这是我找到的另一个解决方案。

  1. 删除已安装的 package react-native-material-dropdown

    yarn remove react-native-material-dropdown

  2. 安装新包react-native-material-dropdown-v2react-native-paper

    yarn add react-native-material-dropdown-v2 react-native-paper

  3. 在代码中将 react react-native-material-dropdown交换为react-native-material-dropdown-v2

    例如import { Dropdown } from 'react-native-material-dropdown'import { Dropdown } from 'react-native-material-dropdown-v2'

我在使用@react-navigation/drawer 时发现了同样的问题

我已经通过这些步骤解决了它。

  1. 打开node_modules然后搜索react-native-material-textfield打开文件和 go 到src文件夹
  2. src下你会看到affix , helper , label文件夹 - 每个文件夹下都有一个index.js
  3. 将上述文件夹的index.js一个一个打开(所有 3 个文件夹)并搜索文本style: Animated.Text.propTypes.style ,并将其替换为style: Text.propTypes
  4. 并导入文本形式 react-native 像这样import { Animated, Text} from 'react-native';
  5. 现在重新加载终端,你对 go 很好

github 上有一个关于这个问题的问题。 正如评论中提到的,可以使用此选项来编辑节点模块,或创建补丁,这样每次添加新库或运行 npm 安装时都无需编辑文件。

操作说明:

  • 在项目的根目录中创建补丁目录
  • 补丁复制到补丁/react-native-material-textfield+0.16.1.patch
  • yarn add patch-package postinstall-postinstall 或 npm i patch-package
  • 纱线补丁包或 npx 补丁包

修复已应用。 在 package.json 中添加以下内容,下次不再重复:

 "scripts": {
+  "postinstall": "patch-package"
 }

https://github.com/n4kz/react-native-material-textfield/issues/249#issuecomment-625791243

我在使用 react-native-material-dropdown 时遇到了同样的问题。

使固定:

  • 导航到node_modules/react-native-material-textfield/src/components
  • 打开文件affix/index.jshelper/index.jslabel/index.js
  • style: Animated.Text.propTypes.style替换为style: Text.propType
  • 在这 3 个文件中的每一个中import { Animated,Text} from 'react-native'

这应该可以解决问题

react-native 版本:0.64.0

只需更新他们用修复更新他们的库的库是链接https://www.npmjs.com/package/react-native-material-dropdown-v2-fixed

我使用react-native-material-textfield 导入前添加我的js文件:

import { Animated, Text } from 'react-native';
Animated.Text.propTypes = Animated.Text.propTypes || Text.propTypes;
import { TextField } from 'react-native-material-textfield';

在此处输入图像描述

I have faced the same issue while using react-native-material-dropdown.

使用此修复:

navigate to node_modules/react-native-material-textfield/src/components
Open files affix/index.js, helper/index.js and label/index.js

我已经通过使用这个库解决了我的问题

react-native-material-dropdown-no-proptypes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM