Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'

Viewed 12023

Since the ViewPropTypes has been removed from 'react-native' and the packages using it didn't update. this error appears after building the app

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.

packages I'm using:

"@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"

Any solution?

5 Answers

I can recommend doing the steps outlined in this github discussion.

Steps

  1. Install patch-package, this will later be used to make the changes more persistent.

  2. Install deprecated-react-native-prop-types by running npm install deprecated-react-native-prop-types or yarn add deprecated-react-native-prop-types

  3. Now you have to hack the node_modules. Go to node_modules/react-native/index.js starting around line 436 and change this:

    // 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'.",
     );
    },
    

to this:

  // 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. Run npx patch-package react-native to save the patch.

  2. Rebuild the app.

Only thing to keep in mind is that this patch will need to be reapplied with every upgrade to react-native, or until the libraries in question are updated to import from deprecated-react-native-prop-types instead.

Props to goguda for providing this answer.

I had the same error I followed the following steps and I resolved it. It arises because react-native has removed the view prop types from the library but still some external modules require the use of it.

  1. Run the command in the terminal
npm i deprecated-react-native-prop-types@2.2.0
  1. Go to the node modules and find the module that you are using in my case it was "react-native-camera"

  2. Navigate into the src folder of the module file (in my case it was in RNCamera.js) and look for

import {
       findNodeHandle,
       Platform,
       NativeModules,
       ViewPropTypes,
       requireNativeComponent,
       View,
       ActivityIndicator,
       Text,
       StyleSheet,
       PermissionsAndroid,
     } from 'react-native';

In the following code remove the ViewPropTypes and paste the following command below this

import { ViewPropTypes } from 'deprecated-react-native-prop-types';

save the file and run it again, Hope it helps <3

I had the same error using react-native-camera. I fix it by installing npm i deprecated-react-native-prop-types@2.2.0 and replacing in node_modules/react-native-camera

all imports in files.

import { ViewPropTypes } from 'react-native'; 

for

import { ViewPropTypes } from 'deprecated-react-native-prop-types';

I had the same issue after upgrading to the new RN v0.69. Changing node_modules/react-native-camera would solve the problem locally. However, we know that when the node dependencies need to be installed from scratch - in a CI/CD process for example - the changes at 3rd party library need to be done over again. So, a better solution I suggest is to intercept the react-native-camera component at build runtime level using the babel-plugin-module-resolver as suggested here https://github.com/psycheangel/deprecated-with-module-resolver. I did another way because this solution did not work for me since it's more generic and got conflict with other stuffs I have on my project. Still using the same babel resolver plugin but to address the specific problem with react-native-camera component, this is the way I did based on the above solution by psycheangel:

Step 1

Install the babel resolver plugin and the turn around dependency:

npm install --save-dev babel-plugin-module-resolver deprecated-react-native-prop-types

or

yarn add --dev babel-plugin-module-resolver deprecated-react-native-prop-types

Step 2

create resolver/react-native/index.js with this code:

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,
}

Step 3

add module resolver plugin config to babel.config.js:

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')
          }
        },
      },
    ],
  ],
}

I had the same error using react-native-snap-carousel. I fix it by replacing in node_modules/react-native-snap-carousel

Check All files and change this import

import { ViewPropTypes } from 'react-native'; 

with this and this error gone

import { ViewPropTypes } from 'deprecated-react-native-prop-types';
Related