Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve 'react-native' - React Native

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"
  }
}
like image 355
Alpesh Trivedi Avatar asked Apr 05 '18 08:04

Alpesh Trivedi


People also ask

How do you fix module not found Cannot resolve in React?

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.

Can not find module react native?

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.

What is module not found error in react JS?

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.


3 Answers

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.

like image 142
qNA Avatar answered Oct 06 '22 22:10

qNA


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

like image 24
Payal Munjewar Avatar answered Oct 06 '22 23:10

Payal Munjewar


To add web support to an existing Expo app you can do the following:

  1. Install the latest version of the Expo CLI: npm i -g expo-cli
  2. Add web dependencies: yarn add react-native-web react-dom
  3. Startup faster in web-only mode by running 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/

like image 26
Vladimir Salguero Avatar answered Oct 06 '22 21:10

Vladimir Salguero