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:
- react-scripts: contains the scripts used in create-react-app.
- react-dom: allows react-code to be rendered into an HTML page
- react-native-web: the main source of magic in this app. This library will convert our react-native components into web elements.
- react-art: a peer dependency for react-native-web
- react-router-native: routing library for React Native
- 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:
- Delete package-lock.json (not package.json!) and/or yarn.lock inyour project folder.
- Delete node_modules in your project folder.
- Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
- 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:
- Install the latest version of the Expo CLI:
npm i -g expo-cli
- Add web dependencies:
yarn add react-native-web react-dom
- Startup faster in web-only mode by running
expo start:web
You can also runexpo start --web
which will start Webpack immediately.