Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 3.35 KB

router-navigation-deps.md

File metadata and controls

47 lines (37 loc) · 3.35 KB

Expo Router navigation dependencies

Expo Router is built on top of React Navigation, and uses React context to control navigation state. Having multiple copies of React Navigation in your project's dependencies can cause conflicts and unexpected behavior.

Most dependency issues can be resolved by running npx expo install --fix in your top level project directory.

If you continue to have issues it may be due to sub-dependencies conflicts, where you may have multiple versions of React Navigation, or the same version of React Navigation installed multiple times. You will need to inspect your dependency tree to determine which of these issues you are experiencing. To output the dependency tree run npm list @react-navigation/native. This command will work even if you are not using npm as your package manager, however you may choose to use similar commands such as yarn why @react-navigation/native.

Multiple versions of React Navigation

$ npm list @react-navigation/native
[email protected] /Github/expo-router
├─┬ [email protected]
│ ├─┬ @react-navigation/[email protected]
│ │ ├─┬ @react-navigation/[email protected]
│ │ │ └── @react-navigation/[email protected]
│ │ └── @react-navigation/[email protected]
│ ├─┬ @react-navigation/[email protected]
│ │ └── @react-navigation/[email protected]
│ └── @react-navigation/[email protected]
└─┬ @react-navigation/[email protected]  # This older version is causing the conflict
  │ ├─┬ @react-navigation/[email protected]
  │ │ └── @react-navigation/[email protected] deduped
  │ └── @react-navigation/[email protected] deduped # Now we have two versions of @react-navigation/native

If a dependency is installing an older version of React Navigation, you will need to update the dependency to use the same version of React Navigation as the rest of your project. Alternatively, you can force the version used by setting a npm overrides or yarn resolutions in your `package.json. However, this may cause issues if the dependency is not compatible with the newer version of React Navigation.

Multiple copies of the same version of React Navigation

$ npm list @react-navigation/native
[email protected] /Github/expo-router
└─┬ [email protected]
  ├─┬ @react-navigation/[email protected]
  │ ├─┬ @react-navigation/[email protected]
  │ │ └── @react-navigation/[email protected] deduped
  │ └── @react-navigation/[email protected] deduped
  ├─┬ @react-navigation/[email protected]
  │ └── @react-navigation/[email protected] # This is not deduped and is nested
  └── @react-navigation/[email protected]

Package managers optimize install time over deduplication and over time this can cause multiple versions of a package being installed. If you see multiple copies of the same version of React Navigation in your dependency tree, you can run either npm dedupe or yarn dedupe to remove these unneeded duplicate dependencies.

Alternatively, you can remove your node_modules folder and your package-lock.json / yarn.lock file and run npm install or yarn install respectively. This will force your package manager to re-resolve the dependency tree.