I'm in the process of re-adding dependencies for a project to bring them up to date, and I see this error message when a dependency is missing. The specific reason for the error -- in my case, which dependency is missing -- is shown in my build logs, which I view in Xcode by double clicking the error in the sidebar. Here's a sample log:
Error: Unable to resolve module @react-navigation/stack from /Users/s/Work/dev/js/myrn/interflexion/navigation/MainStack.js: @react-navigation/stack could not be found within the project or in these directories:
node_modules
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
[0m [90m 1 |[39m [36mimport[39m [33mReact[39m [36mfrom[39m [32m'react'[39m[33m;[39m[0m
[0m [90m 2 |[39m [36mimport[39m { [33mView[39m[33m,[39m [33mImageBackground[39m[33m,[39m [33mButton[39m } [36mfrom[39m [32m'react-native'[39m[0m
[0m[31m[1m>[22m[39m[90m 3 |[39m [36mimport[39m { createStackNavigator } [36mfrom[39m [32m'@react-navigation/stack'[39m[33m;[39m[0m
[0m [90m |[39m [31m[1m^[22m[39m[0m
[0m [90m 4 |[39m[0m
[0m [90m 5 |[39m[0m
[0m [90m 6 |[39m[0m
at ModuleResolver.resolveDependency (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:129:15)
at DependencyGraph.resolveDependency (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/node-haste/DependencyGraph.js:288:43)
at Object.resolve (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/lib/transformHelpers.js:129:24)
at resolve (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
at /Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
at Array.reduce ()
at resolveDependencies (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
at processModule (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:140:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async addDependency (/Users/s/Work/dev/js/myrn/interflexion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:230:18)
info Run CLI with --verbose flag for more details.
Command PhaseScriptExecution failed with a nonzero exit code