Unable to resolve "@react-navigation/native" from "App.js" - React Native + How to Solve?
S

9

25

undefined Unable to resolve module @react-navigation/native from App.js: @react-navigation/native could not be found within the project.

If you are sure the module exists, try these steps:

 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
- node_modules\react-native\Libraries\Utilities\HMRClient.js:307:41 in showCompileError
- node_modules\react-native\Libraries\Utilities\HMRClient.js:228:26 in client.on$argument_1
- node_modules\eventemitter3\index.js:181:39 in emit
- node_modules\metro\src\lib\bundle-modules\WebSocketHMRClient.js:80:20 in _ws.onmessage
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\WebSocket\WebSocket.js:232:27 in _eventEmitter.addListener$argument_1
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
> Unable to resolve "@react-navigation/native" from "App.js"
Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
Error: Can't find react-native in package.json dependencies
Error: Can't find react-native in package.json dependencies

enter image description here

Please Help Me. Email ID: [email protected]

Saracen answered 1/4, 2020 at 16:4 Comment(2)
Followed all the steps given in this getting started guide? reactnavigation.org/docs/getting-startedAlignment
if you are already running the app and at the same time installed the dependencies, then you have to relaunch it.Zerla
C
31
npm install @react-navigation/native

if using expo:

expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view

Also run:

npm install react-navigation
Collinsia answered 9/5, 2020 at 10:0 Comment(2)
Why do we need all these dependencies?Autography
Also restart the server after running these commands ;)Grose
U
14

This error occurs because you haven't installed react-navigation.

Run:

npm install react-navigation
npm start -- --reset-cache
Urgent answered 1/4, 2020 at 17:58 Comment(0)
T
7

the best solution is to delete your node_modules and package-lock.json and try npm install, it worked for me

Tertias answered 9/1, 2021 at 7:2 Comment(1)
This seems straight forward but it worksForklift
H
2

well i have solved this by reinstalling / updating these packages.

npm install --save react-native-gesture-handler react-native-reanimated react-native-screens

do the trick for

npm start -- --reset-cache

But performing the following did succeed:

Delete

node_modules & package-lock.json Delete app from phone

run npm start -- --reset-cache
run app
Hyperplasia answered 14/12, 2020 at 1:18 Comment(0)
P
2

Try to add this line to your metro.config.js

sourceExts: ['jsx', 'js', 'ts', 'tsx', 'json'],
Phillipp answered 7/3, 2021 at 6:20 Comment(0)
M
1

Also, you have to restart your app, do npm run... to start a new server if you are using expo.

Mideast answered 19/12, 2021 at 14:2 Comment(0)
H
1

This error is due to stale cache. To fix this, Run: npm start -c //This is if you're using expo

if you're not using expo, Run: npx react-native start --reset-cache

Hittel answered 30/11, 2022 at 14:15 Comment(0)
G
0

I have been stuck on same issue for a whole day at last deleting packagelock.json and node module folder with using

try resetting the cache

after that npm start

and at last run: npx react-native run-android

and now all the files will be rebuild and your navigation container should be working

Girdler answered 21/6, 2022 at 6:50 Comment(0)
C
0

I came across this question when I was looking for a solution as I had a similar problem. You can use yarn commands in the documentation instead of npm.

If it persits, change

import { NavigationContainer } from '@react-navigation/native';

to:

import { NavigationContainer } from './node_modules/@react-navigation/native;

I had made that changes before using the yarn commands

While running the build, use:

npx react-native start
Copious answered 26/1, 2023 at 1:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.