React Native problem: WebView has been removed from React Native

Andrew Terex picture Andrew Terex · Dec 12, 2019 · Viewed 7.1k times · Source

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.

Answer

sagar dhiman picture sagar dhiman · Dec 26, 2019

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/' }} />