6

When I run my react-native app with Xcode, and after the app starts to load, I see this error:

"Requiring unknown module "react". If you are sure the module is there, try restarting the packager."

My package.json contents are:

{
  "name": "the_golf_mentor",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "react-native": "^0.21.0",
    "react-native-button": "^1.4.2",
    "react-native-cookies": "^0.0.5",
    "react-native-db-models": "^0.1.3",
    "react-native-navbar": "^1.2.1",
    "react-native-side-menu": "^0.18.0",
    "tcomb-form-native": "^0.3.3"
  }
}

I have tried restarting the package manager, and I have also removed the node_module folder and done a fresh npm install. How do I fix this problem?

2
  • 1
    try to install React also, like npm install --save react Commented Mar 14, 2016 at 9:09
  • @MotiAzu All packages are lower-case only. Commented Mar 14, 2016 at 9:11

6 Answers 6

8

I had this after enabling hot reloading, and then downgrading my react version to support a library I was using.

Simulator > Reset Content and Settings

Got it running again.

1
  • This worked and I don't know why. How can deleting the app not work but wiping the simulator can, when the problem resides from React. Anyway, this worked. Commented Apr 8, 2019 at 9:47
3

In React Native React lives in react-native module instead of react (for React JS). In that case import React and other React Native modules via:

import React, {
    Component,
    View,        
    Text,
    // other React Native modules
} from 'react-native';
1
  • 1
    This is no longer the case (I think since 0.25)
    – Tom
    Commented May 25, 2016 at 8:24
2

I encountered the same error. I closed down IDE and restarted, it worked for me. If nothing works out, try npm install

0
1

I had similar issue: "Error: Requiring Unknown module 3" after installing '@react-navigation/native', so I did the following to fix it:

  1. Close everything (Metro, Debugger and Simulator)
  2. npm install
  3. npx pod-install ios (On Mac)
  4. npm run ios

and that's it!

0

You should require React from react-native in a react-native project, and not from react.

var React = require('react-native');
2
0

It turned out that the error message was an interim one I was receiving in the debugger. When I pressed continue a couple of times in the debugger, I received a message in the simulator window which indicated I had not registering the app properly, i.e. my AppRegistry.registerComponent call was invalid.

I suspect this was an unusual cause of the unknown module 'react' error message. In many cases, neciu's answer is probably more useful, so I have also upvoted it as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.