React Native 问题:WebView 已从 React Native 中移除

And*_*rex 5 mobile android reactjs react-native react-native-webview

我昨天使用 react-native-cli 构建了新的 React Native 项目。但是当用我的安卓手机运行这个项目时,我在红屏上出现了这个错误。

不变违规:WebView 已从 React Native 中删除。现在可以从“react-native-webview”而不是“react-native”安装和导入它。请参阅“ https://github.com/react-native-community/react-native-webview ”。

我从未使用过 WebView,这是我的“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"
  }
}
Run Code Online (Sandbox Code Playgroud)

我试图解决这个问题一整天,但我不能。我只是认为 'react-native-gesture-handler' 会导致这个问题。任何对 React-Native 有丰富经验的人,请帮助我。谢谢你。

sag*_*man 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'
Run Code Online (Sandbox Code Playgroud)

使用网络视图作为:

<WebView source={{ uri: 'https://facebook.github.io/react-native/' }} />
Run Code Online (Sandbox Code Playgroud)


use*_*384 0

尝试

  1. 删除 android 文件夹和 ios 文件夹中的所有构建文件
  2. 删除你的node_modules
  3. npm 安装
  4. 尝试再次运行它