错误:无法从`index.js`解析模块`react`:在项目中找不到react

Rag*_*ngh 7 react-native react-native-android react-native-ios

错误:无法reactindex.js以下位置解析模块:在项目中找不到反应。

当我尝试运行我的项目时,它会给我这个捆绑失败的错误。

在此处输入图片说明

这是我的 index.js 文件代码。

/**
 * @format
 */
import React,{Component} from 'react';
import {AppRegistry} from 'react-native';
import {name as appName} from './app.json';
import src from './Screens/Search'
import AppContainer from "./Component/MainNavigation";
class myApp extends Component {
    render(){
        return(
            <AppContainer />
        )
    }

}
AppRegistry.registerComponent(appName, () => myApp);
Run Code Online (Sandbox Code Playgroud)

package.json 文件。

{
  "name": "CharityDating",
  "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": {
    "@ptomasroos/react-native-multi-slider": "^1.0.0",
    "@react-native-community/masked-view": "^0.1.6",
    "react": "16.9.0",
    "react-native": "^0.61.5",
    "react-native-animatable": "^1.3.3",
    "react-native-country-picker-modal": "^1.10.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-draggable": "^3.0.0",
    "react-native-draggable-grid": "^1.2.1",
    "react-native-gesture-handler": "^1.5.3",
    "react-native-image-picker": "^2.0.0",
    "react-native-image-slider": "^2.0.3",
    "react-native-keyboard-aware-scrollview": "^2.1.0",
    "react-native-pulse": "^1.0.7",
    "react-native-reanimated": "^1.7.0",
    "react-native-responsive-fontsize": "^0.4.2",
    "react-native-responsive-screen": "^1.3.1",
    "react-native-safe-area-context": "^0.6.2",
    "react-native-safe-area-view": "^1.0.0",
    "react-native-slider": "^0.11.0",
    "react-native-sortable-grid": "^2.0.0",
    "react-native-switch-toggle": "^1.1.4",
    "react-navigation": "^4.0.10",
    "react-navigation-stack": "^2.0.13",
    "react-navigation-tabs": "^2.7.0",
    "react-toggle": "^4.1.1",
    "responsive-image": "^0.3.1",
    "toggle-switch-react-native": "^2.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}
Run Code Online (Sandbox Code Playgroud)

Rag*_*ngh 8

我再次安装了react。使用'npm i react'并解决了错误。


Pra*_*ena 5

这个错误可能与 npm 安装有关,试试这个:

解决方案1follow the steps given with your error to resolve this error

解决方案2:

npm start -- --reset-cache

then

react-native run-android // in separate command line
Run Code Online (Sandbox Code Playgroud)

解决方案3:

  Delete node_modules folder and package-lock.json file 

  => npm install
Run Code Online (Sandbox Code Playgroud)