7

Error: Unable to resolve module react from index.js: react could not be found within the project.

When i tried to run my project then it will give me this bundling failed error.

enter image description here

Here is my index.js file code.

/**
 * @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);

package.json file.

{
  "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"
  }
}
5
  • 1
    Can you post your package.json ? Commented Jan 31, 2020 at 8:51
  • Yes i can post package,json file @mindmaster Commented Jan 31, 2020 at 9:02
  • you can add react manually using yarn add react and try again Commented Jan 31, 2020 at 9:25
  • Try to install the last version of react which is 16.12.0. And then follow the steps from @prakash-karena post. Commented Jan 31, 2020 at 9:51
  • In my case, I had from "React" instead of from "react". I guess at React 16.9+, it became case sensitive. Commented Apr 27, 2021 at 18:47

3 Answers 3

10

I installed react again once more.Using 'npm i react' and error is solved.

Sign up to request clarification or add additional context in comments.

Comments

6

This error is might be related to npm installation try this out :

Solution 1 : follow the steps given with your error to resolve this error

Solution 2 :

npm start -- --reset-cache

then

react-native run-android // in separate command line

Solution 3 :

  Delete node_modules folder and package-lock.json file 

  => npm install

4 Comments

let me know if you have any query
I did it .But there is same issue.
have you intalled your all packages in root directory ?? npm install
Yes.But i will check it again.@Prakash Karena
3

Just went through the same error after adding typescript. I solved it by adding json extension to resolver in metro.config.js

module.exports = {
    resolver: {
        sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs', 'json'],
      }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.