android – React Native problem: WebView has been removed from React Native-ThrowExceptions

Exception or error:

I built new React Native project yesterday using react-native-cli.
But when running the project with my android phone, I got this error in red screen.

Invariant Violation: WebView has been removed from React Native. It can now be installed and imported from ‘react-native-webview’ instead of ‘react-native’. See ‘https://github.com/react-native-community/react-native-webview‘.

I never used WebView and here is my “package.json”.

{
  "name": "",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-image-slider": "^2.0.3",
    "react-native-svg": "^9.13.6",
    "react-navigation": "^4.0.10",
    "react-navigation-drawer": "^2.3.3",
    "react-navigation-stack": "^1.10.3",
    "react-redux": "^7.1.3",
    "redux": "^4.0.4"
  },
  "devDependencies": {
    "@babel/core": "^7.7.5",
    "@babel/runtime": "^7.7.6",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.7.2",
    "install-peers": "^1.0.3",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.57.0",
    "react-native-gesture-handler": "^1.5.2",
    "react-native-reanimated": "^1.4.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

I tried to fix this problem for a whole day but I couldn’t.
I just think ‘react-native-gesture-handler’ causes this problem.
Anyone who has much experience of React-Native, please help me.
Thank you.

How to solve:

Run this command in your root folder:
npm i react-native-webview


Please see this npm package first

https://www.npmjs.com/package/react-native-webview


Run the project again in your android and IOS device with this command: react-native run-android or react-native run-ios


import the package :
import { WebView } from ‘react-native-webview’;


Use webview as:

<WebView source={{ uri: 'https://facebook.github.io/react-native/' }} />

###

Try to

  1. delete all your build-files in android folder and ios folder
  2. delete your node_modules
  3. npm install
  4. Try to run it again

###

I think it’s clearly mentioned there in the warning:

WebView has been removed from React Native. It can now be installed and imported from ‘react-native-webview‘ instead of ‘react-native’

I suppose you are now using the following some where in your code

import {
  WebView,
} from 'react-native';

Now onwards you shall do the following instead
import { WebView } from 'react-native-webview';

To get started with react-native-webivew, you can follow the getting started document here

Leave a Reply

Your email address will not be published. Required fields are marked *