首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不变违反: ViewPropTypes已从中删除。迁移到从“反推荐-反应-本机-支柱类型”导出的ViewPropTypes

不变违反: ViewPropTypes已从中删除。迁移到从“反推荐-反应-本机-支柱类型”导出的ViewPropTypes
EN

Stack Overflow用户
提问于 2022-06-25 16:20:39
回答 6查看 26.6K关注 0票数 30

因为ViewPropTypes已经从“react原生”中删除了,并且使用它的包没有更新。此错误出现在生成应用程序之后。

代码语言:javascript
运行
复制
ERROR  Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.   
ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

我正在使用的软件包:

代码语言:javascript
运行
复制
"@react-native-clipboard/clipboard": "^1.10.0",
"@react-native-community/checkbox": "^0.5.12",
"@react-native-firebase/app": "^14.11.0",
"@react-native-firebase/auth": "^14.9.4",
"@react-native-firebase/database": "^14.11.0",
"@react-native-firebase/firestore": "^14.11.0",
"@react-native-google-signin/google-signin": "^7.2.2",
"@react-native-masked-view/masked-view": "github:react-native-masked-view/masked-view",
"@react-native-picker/picker": "^2.4.1",
"@react-navigation/bottom-tabs": "^6.3.1",
"@react-navigation/native": "^6.0.10",
"@react-navigation/stack": "^6.2.1",
"axios": "^0.27.2",
"base-64": "^1.0.0",
"num-words": "^1.2.2",
"numeral": "^2.0.6",
"pdf-lib": "^1.17.1",
"react": "17.0.2",
"react-native": "^0.69.0",
"react-native-blob-util": "^0.16.1",
"react-native-country-picker-modal": "^2.0.0",
"react-native-date-picker": "^4.2.2",
"react-native-fbsdk-next": "^8.0.5",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.5.0",
"react-native-html-to-pdf": "^0.12.0",
"react-native-pdf": "^6.5.0",
"react-native-picker-select": "^8.0.4",
"react-native-progress": "^5.0.0",
"react-native-radio-input": "^0.9.4",
"react-native-ratings": "^8.1.0",
"react-native-safe-area-context": "^4.2.5",
"react-native-screens": "^3.13.1",
"react-native-share": "^7.5.0",
"react-native-signature-canvas": "^4.3.1",
"react-native-vector-icons": "^9.1.0",
"react-native-webview": "^11.21.2",
"react-scripts": "^5.0.1"

有解决办法吗?

EN

Stack Overflow用户

发布于 2022-07-21 16:17:34

在升级到新的RNv0.69之后,我也遇到了同样的问题。改变node_modules/react-native-camera将在本地解决问题。但是,我们知道,当节点依赖关系需要从头安装时(例如在CI/CD过程中),第三方库中的更改需要再次进行。因此,我建议的一个更好的解决方案是使用babel-plugin-module-resolver在构建运行时级别拦截https://github.com/psycheangel/deprecated-with-module-resolver组件,如这里所建议的https://github.com/psycheangel/deprecated-with-module-resolver。我做了另一种方式,因为这个解决方案不适合我,因为它更通用,并且与我的项目中的其他东西有冲突。仍然使用相同的babel解析器插件,但是为了解决react-native-camera组件的具体问题,我采用了心理天使基于上述解决方案的方法

第一步

安装babel解析器插件和转身依赖:

代码语言:javascript
运行
复制
npm install --save-dev babel-plugin-module-resolver deprecated-react-native-prop-types

代码语言:javascript
运行
复制
yarn add --dev babel-plugin-module-resolver deprecated-react-native-prop-types

第二步

使用以下代码创建resolver/react-native/index.js

代码语言:javascript
运行
复制
import * as ReactNative from 'react-native'
import * as DeprecatedPropTypes from 'deprecated-react-native-prop-types'

delete ReactNative['ColorPropType']
delete ReactNative['EdgeInsetsPropType']
delete ReactNative['ImagePropTypes']
delete ReactNative['PointPropType']
delete ReactNative['TextInputPropTypes']
delete ReactNative['TextPropTypes']
delete ReactNative['ViewPropTypes']

module.exports = {
  ...ReactNative,
  ...DeprecatedPropTypes,
}

第三步

将模块解析器插件配置添加到babel.config.js

代码语言:javascript
运行
复制
const path = require('path')
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'module-resolver',
      {
        root: ['.'],
        resolvePath(sourcePath, currentFile) {
          if (
            sourcePath === 'react-native' &&
            currentFile.includes('react-native-camera/src/RNCamera.js')
          ) {
            console.log('resolver', sourcePath, currentFile)
            return path.resolve(__dirname, 'resolver/react-native')
          }
        },
      },
    ],
  ],
}
票数 -1
EN
查看全部 6 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72755476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档