(0,n.usePreventRemoveContext) is not a function error

(0,n.usePreventRemoveContext) is not a function error

See this snack

What is this error happening. There is no solution in goggle for it

@amanhimself can you explain this issue

It seems like the issue might be related to compatibility for React Navigation libraries in your project. See this: android - React Navigation v6 usePreventRemoveContext is undefined error - Stack Overflow.

In your project’s package.json, you’ve multiple instances of react navigation library. For example:

  "react-navigation": "^4.4.4",  // <--
    "react-navigation-stack": "^2.10.4",
    "@react-navigation/stack": "^6.3.17",
    "@react-navigation/native": "6.0.0", // <--

Please update your dependencies to use latest React Navigation library (version 6 and above) and remove older version libraries such as "react-navigation": "^4.4.4".

1 Like

Hi,
now the problem is showing
Unable to resolve module ‘module://moment.js’
but this problem is not showing when I have run the expo from my desktop and testing on my device.

now my packages are below

{
  "dependencies": {
    "axios": "^0.27.2",
    "expo-font": "~11.0.1",
    "jwt-decode": "^3.1.2",
    "expo-camera": "~13.1.0",
    "expo-sensors": "~12.0.1",
    "expo-updates": "~0.15.6",
    "expo-contacts": "~11.0.1",
    "expo-constants": "~14.0.2",
    "expo-status-bar": "~1.4.2",
    "expo-app-loading": "~2.1.1",
    "react-native-svg": "13.4.0",
    "expo-image-picker": "~14.0.2",
    "@expo/vector-icons": "^13.0.0",
    "expo-splash-screen": "~0.17.5",
    "react-native-modal": "^13.0.1",
    "react-native-paper": "^4.12.2",
    "expo-barcode-scanner": "~12.1.0",
    "react-native-screens": "~3.18.0",
    "react-native-progress": "^5.0.0",
    "@react-navigation/stack": "^6.3.17",
    "react-native-keep-awake": "^4.0.0",
    "react-native-qrcode-svg": "*",
    "react-native-vector-icons": "^9.2.0",
    "@react-navigation/elements": "latest",
    "react-native-gesture-handler": "~2.8.0",
    "@react-navigation/bottom-tabs": "*",
    "@react-navigation/native-stack": "^6.7.0",
    "react-native-safe-area-context": "4.4.1",
    "@react-native-community/datetimepicker": "6.5.2",
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@expo/vector-icons/Ionicons": "^13.0.0",
    "@react-navigation/native": "6.0.0",
    "moment/moment": "*",
    "moment": "*"
  }
}

Try removing moment/moment

I have remove that
and now problem is showing
(0,n.usePreventRemoveContext) is not a function. (In ‘(0,n.usePreventRemoveContext)()’, ‘(0,n.usePreventRemoveContext)’ is undefined)

my packages are below

{
  "dependencies": {
    "axios": "^0.27.2",
    "moment": "*",
    "expo-font": "~11.0.1",
    "jwt-decode": "^3.1.2",
    "expo-camera": "~13.1.0",
    "expo-sensors": "~12.0.1",
    "expo-updates": "~0.15.6",
    "expo-contacts": "~11.0.1",
    "expo-constants": "~14.0.2",
    "expo-status-bar": "~1.4.2",
    "expo-app-loading": "~2.1.1",
    "react-native-svg": "13.4.0",
    "expo-image-picker": "~14.0.2",
    "@expo/vector-icons": "^13.0.0",
    "expo-splash-screen": "~0.17.5",
    "react-native-modal": "^13.0.1",
    "react-native-paper": "^4.12.2",
    "expo-barcode-scanner": "~12.1.0",
    "react-native-screens": "~3.18.0",
    "react-native-progress": "^5.0.0",
    "@react-navigation/stack": "^6.3.17",
    "react-native-keep-awake": "^4.0.0",
    "react-native-qrcode-svg": "*",
    "@react-navigation/native": "6.0.0",
    "react-native-vector-icons": "^9.2.0",
    "@react-navigation/elements": "latest",
    "@expo/vector-icons/Ionicons": "^13.0.0",
    "react-native-gesture-handler": "~2.8.0",
    "@react-navigation/bottom-tabs": "*",
    "@react-navigation/native-stack": "^6.7.0",
    "react-native-safe-area-context": "4.4.1",
    "@react-native-community/datetimepicker": "6.5.2",
    "@react-native-async-storage/async-storage": "~1.17.3"
  }
}

Have you saved your snack? I still see this:

components/RecentTransactions.js

import moment from "moment/moment";

and there are still old versions of React Navigation in package.json:

    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4",

In the dependencies posted above you have the following dependencies:

    "@react-navigation/stack": "^6.3.17",
    "@react-navigation/native": "6.0.0",
    "@react-navigation/elements": "latest",
    "@react-navigation/bottom-tabs": "*",
    "@react-navigation/native-stack": "^6.7.0",

@react-navigation/elements should be pulled in by the other React Navigation modules that need it, so I think you can remove it.

It’s worth trying to upgrade these to see if there’s some sort of version conflict. I checked the React Navigation docs and did this:

$ yarn add @react-navigation/native
$ npx expo install react-native-screens react-native-safe-area-context
$ yarn add @react-navigation/stack
$ npx expo install react-native-gesture-handler
$ yarn add @react-navigation/native-stack
$ yarn add @react-navigation/bottom-tabs
$ yarn remove @react-navigation/elements

After doing the above I ended up with these dependencies:

  "dependencies": {
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@react-native-community/datetimepicker": "6.5.2",
    "@react-navigation/bottom-tabs": "^6.5.8",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "@react-navigation/stack": "^6.3.17",
    "axios": "^0.27.2",
    "expo": "^47.0.0",
    "expo-app-loading": "~2.1.1",
    "expo-barcode-scanner": "~12.1.0",
    "expo-camera": "~13.1.0",
    "expo-constants": "~14.0.2",
    "expo-contacts": "~11.0.1",
    "expo-font": "~11.0.1",
    "expo-image-picker": "~14.0.2",
    "expo-sensors": "~12.0.1",
    "expo-splash-screen": "~0.17.5",
    "expo-status-bar": "~1.4.2",
    "expo-updates": "~0.15.6",
    "jwt-decode": "^3.1.2",
    "moment": "*",
    "react": "18.1.0",
    "react-dom": "18.1.0",
    "react-native": "0.70.8",
    "react-native-gesture-handler": "~2.8.0",
    "react-native-keep-awake": "^4.0.0",
    "react-native-modal": "^13.0.1",
    "react-native-paper": "^4.12.2",
    "react-native-progress": "^5.0.0",
    "react-native-qrcode-svg": "*",
    "react-native-safe-area-context": "4.4.1",
    "react-native-screens": "~3.18.0",
    "react-native-svg": "13.4.0",
    "react-native-vector-icons": "^9.2.0",
    "react-native-web": "~0.18.7"
  },

Also I see you have both @react-navigation/stack and @react-navigation/native-stack installed. I suspect you want just one of these.

If you’re still getting this error after making the above changes, please elaborate on where/how you’re seeing it. Are you using Expo Go to connect to the Snack? Are you running it locally on your machine with a development build? Which screen are you getting it on? etc.

1 Like