'React-native error requiring unknown module 'react'
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?
Solution 1:[1]
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.
Solution 2:[2]
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';
Solution 3:[3]
I encountered the same error. I closed down IDE and restarted, it worked for me. If nothing works out, try npm install
Solution 4:[4]
You should require React from react-native in a react-native project, and not from react.
var React = require('react-native');
Solution 5:[5]
I had similar issue: "Error: Requiring Unknown module 3" after installing '@react-navigation/native', so I did the following to fix it:
- Close everything (Metro, Debugger and Simulator)
- npm install
- npx pod-install ios (On Mac)
- npm run ios
and that's it!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tom |
| Solution 2 | neciu |
| Solution 3 | Malith Senanayake |
| Solution 4 | Moti Azu |
| Solution 5 | A.Z |
