6

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.

4

4 回答 4

5

在您的根文件夹中运行此命令: npm i react-native-webview


请先看这个 npm 包

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


使用以下命令在您的 android 和 IOS 设备中再次运行项目:react-native run-android 或 react-native run-ios


导入包:

import { WebView } from 'react-native-webview'

使用 webview 作为:

<WebView source={{ uri: 'https://facebook.github.io/react-native/' }} />
于 2019-12-26T12:13:16.953 回答
1

基本上你的猜测是正确的,它受react-native-gesture-handler.

原因

这是依赖于 webview 的文件。
https://github.com/software-mansion/react-native-gesture-handler/blob/1.0.10/GestureHandler.js

解决方案

  1. react-native-gesture-handler将已经将 webview 从 react-native 替换为 react-native-webview 的最新版本升级到
  2. 运行yarn install并重建您的项目
于 2021-05-28T08:59:22.207 回答
0

尝试

  1. 删除 android 文件夹和 ios 文件夹中的所有构建文件
  2. 删除你的 node_modules
  3. npm 安装
  4. 尝试再次运行它
于 2019-12-12T02:30:07.450 回答
-1

我认为警告中明确提到了它:

WebView已从 React Native中删除。现在可以从“ react-native-webview ”而不是“react-native”安装和导入它

我想你现在在你的代码中使用以下一些地方

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

从现在开始,您将改为执行以下操作 import { WebView } from 'react-native-webview';

要开始使用 react-native-webivew,您可以按照此处的入门文档进行操作

于 2019-12-12T03:39:57.307 回答