Home > Software engineering >  NetInfo has been removed from React Native
NetInfo has been removed from React Native

Time:11-06

Before you try to automatically delete this as a duplicate, hear me out. I have spent all day googling this and trying everything.

My project is a React Native app using Expo.

Recently, when I was adding some packages to get testing working, I started to get this error:

Invariant Violation: NetInfo has been removed from React Native. It can now be installed and imported from '@react-native-community/netinfo' instead of 'react-native'. See https://github.com/react-native-community/react-native-netinfo

As people suggested, I tried searching through my Node Modules folder for any old style imports of the netInfo package, but there were none. I have tried rolling back my node modules to a previous state from and older commit by deleting the node_modules folder, replacing package.json with an older setup that I know worked and npm i to reinstall.

I need something else to try.

Here is my package.json that I know worked in the past, but is giving me the error anyway

{

  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"

  },
  "dependencies": {
    "@expo/vector-icons": "^12.0.5",
    "@fortawesome/fontawesome-svg-core": "^1.2.36",
    "@fortawesome/free-regular-svg-icons": "^5.15.4",
    "@fortawesome/free-solid-svg-icons": "^5.15.4",
    "@fortawesome/react-native-fontawesome": "^0.2.7",
    "@react-native-async-storage/async-storage": "^1.15.9",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/stack": "^6.0.7",
    "@redux-offline/redux-offline": "^2.6.0-expo.0",
    "expo": "^42.0.3",
    "expo-app-loading": "1.1.2",
    "expo-location": "~12.1.2",
    "expo-sqlite": "~9.2.1",
    "expo-status-bar": "~1.0.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
    "react-native-get-random-values": "^1.7.0",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "~3.4.0",
    "react-native-web": "~0.13.12",
    "react-redux": "^7.2.5",
    "redux": "^4.1.1",
    "redux-thunk": "^2.3.0",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "eslint": "^8.1.0",
    "eslint-plugin-react": "^7.26.1",
    "eslint-plugin-react-native": "^3.11.0",
    "redux-devtools-extension": "^2.13.9"

  },
  "private": true

}

CodePudding user response:

Looking at the official Expo docs on NetInfo, you simply need to install the suggested NetInfo module

Just run expo install @react-native-community/netinfo to get the dependency and change your imports to

import NetInfo from '@react-native-community/netinfo';

I am pretty sure the API is the same, so the import change should be enough. Read the docs just to be sure.

CodePudding user response:

Recently, when I was adding some packages to get testing working

Since NetInfo is not used directly in your code, I imagine that one of the packages you recently added is still attempting to access NetInfo via React Native.

First you'll need to determine which package is causing this. Then either update it to a newer version which imports NetInfo from @react-native-community/netinfo, or remove the package entirely.

  • Related