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

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


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.


Your project can't see the react-native package. If you already have all required dependencies installed (for use of react-native) go the end of this post. if not, I suggest you have the following:

  1. react-scripts: contains the scripts used in create-react-app.
  2. react-dom: allows react-code to be rendered into an HTML page
  3. react-native-web: the main source of magic in this app. This library will convert our react-native components into web elements.
  4. react-art: a peer dependency for react-native-web
  5. react-router-native: routing library for React Native
  6. react-router-dom: routing library for React on the web

========================================================================

First thing first, you need compatible babel-jest dependencies. To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock inyour project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

The above configuration do not require you to have webpack manually configured, because react-scripts does that.

Maybe you don't use all that nor even react-scripts, so you must have to configure your webpack.config.js. To fix this, try the following:

const path = require('path')module.exports = ({platform}, defaults) => ({  ...defaults,  entry: './index.js',  /* ... */  resolve: {    ...defaults.resolve,    alias: {       ...defaults.resolve.alias,      react: path.join(__dirname, 'node_modules/react'),      'react-native': path.join(__dirname, 'node_modules/react-native'),    }  }})


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/