我昨天使用react-native-cli构建了新的React Native项目。 但是当我用我的 Android 手机运行该项目时,我在红屏中遇到了这个错误。
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'.
我从未使用过 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"
}
}
我尝试了一整天来解决这个问题,但没有成功。 我只是认为“react-native-gesture-handler”导致了这个问题。 任何有丰富 React-Native 经验的人请帮助我。 谢谢。
最佳答案
在根文件夹中运行此命令: npm 我 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/' }} />
关于android - React Native问题: WebView has been removed from React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59296690/