I have just started learning React Native and wanted to add input fields to the page. I have gone through this tutorial to add input fields. But whenever I run the React App it throws the following error.
./src/Inputs.js
Module not found: Can't resolve 'react-native' in 'E:\hybrid\reactDemo\src'
I have checked if the react-native node-modules is there or not, then I came to know that the module react-native was not there. I installed it run the app again, but it shows the same error. I have spent more than 8 hours on this but unable to resolve this error. I have tried out all the solution from google but none of them worked for me.
Note: I am using windows PC
Update 1: I am importing react-native like following
import { View, Text, TouchableOpacity, TextInput, StyleSheet } from 'react-native'
Update 2:
This is my package.json file
{
"name": "reactDemo",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-native": "^0.54.4",
"react-router": "^3.0.5",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
To solve the "Module not found: Can't resolve" error in React, make sure to install the package from the error message if it's a third party package, e.g. npm i somePackage . If you got the error when importing local files, correct your import path.
To solve the "Cannot find module react or its corresponding type declarations" error, install the module and its type definitions by running the commands npm install react and npm i --save-dev @types/react . Copied! Now you should be able to import the react library with the following line of code.
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies. The module you're trying to import is in a different directory. The module you're trying to import has a different casing.
I'm not sure but in my case it helped to install react native web by npm install react-native-web
. Hope it helps you too.
You are trying to add react-native in other react project. React Native is like React, but it uses native components instead of web components as building blocks. So install react-native using npm install -g react-native-cli in a new folder and then initiate new react-native project using react-native init ProjectName.
Run react-native run-ios / run-android inside your React Native project folder
Reference
To add web support to an existing Expo app you can do the following:
npm i -g expo-cli
yarn add react-native-web react-dom
expo start:web
You can also run expo start --web
which will start Webpack immediately.Source https://docs.expo.io/guides/running-in-the-browser/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With