Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes expo

  1. 安装 patch-package,这将在以后用于使更改更加持久。

  2. 安装 deprecated-react-native-prop-types 通过运行 npm install deprecated-react-native-prop-types or yarn add deprecated-react-native-prop-types

  3. 现在必须破解node_modules。进入node_modules/react-native/index.js,从第436行开始修改:

    // Deprecated Prop Types
    get ColorPropType(): $FlowFixMe {
      invariant(
        false,
        "ColorPropType has been removed from React Native. Migrate to " +
          "ColorPropType exported from 'deprecated-react-native-prop-types'.",
     );
    },
    get EdgeInsetsPropType(): $FlowFixMe {
      invariant(
        false,
        "EdgeInsetsPropType has been removed from React Native. Migrate to " +
          "EdgeInsetsPropType exported from 'deprecated-react-native-prop-types'.",
      );
    },
    get PointPropType(): $FlowFixMe {
      invariant(
        false,
        "PointPropType has been removed from React Native. Migrate to " +
         "PointPropType exported from 'deprecated-react-native-prop-types'.",
     );
    },
    get ViewPropTypes(): $FlowFixMe {
     invariant(
       false,
       "ViewPropTypes has been removed from React Native. Migrate to " +
         "ViewPropTypes exported from 'deprecated-react-native-prop-types'.",
     );
    },
    

修改为:

  // Deprecated Prop Types
  get ColorPropType(): $FlowFixMe {
    return require("deprecated-react-native-prop-types").ColorPropType
  },
  get EdgeInsetsPropType(): $FlowFixMe {
    return require("deprecated-react-native-prop-types").EdgeInsetsPropType
  },
  get PointPropType(): $FlowFixMe {
    return require("deprecated-react-native-prop-types").PointPropType
  },
  get ViewPropTypes(): $FlowFixMe {
    return require("deprecated-react-native-prop-types").ViewPropTypes
  },
  1. 执行npx patch-package react-native命令保存补丁。

  2. 在package.json文件中加入 ,"postinstall": "patch-package"

  3. 重新构建应用程序。

原文有很多,筛选出来为有用的
原地址:Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types' - Stack Overflow

猜你喜欢

转载自blog.csdn.net/AS32H1/article/details/127919830