All my react-native projects shows error TypeError: cb.apply is not a function

Viewed 17239

I'm realtively new to react-native. All my projects were running fine in the morning, but somehow they stopped working. When I run react-native start and the react-native run-android, the app gets installed on the device but then this error props up which was not happening before.

Loading dependency graph, done.
 DELTA  [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1)/home/yehyaumar/Documents/dumm/busybee/node_modules/graceful-fs/polyfills.js:285
        if (cb) cb.apply(this, arguments)
                   ^

TypeError: cb.apply is not a function
    at /home/yehyaumar/Documents/dumm/busybee/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqCallback.oncomplete (fs.js:169:5)

I even cloned the repo from from scratch, but still the error persists. Please help out. RN version: 0.59.2

My package.json file for one project,

{
  "name": "projectalpha",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.11.0",
    "axios": "^0.18.0",
    "react": "16.8.3",
    "react-native": "0.59.2",
    "react-native-awesome-alerts": "^1.2.0",
    "react-native-circle-checkbox": "^0.1.6",
    "react-native-circular-progress": "^1.1.0",
    "react-native-gesture-handler": "^1.1.0",
    "react-native-google-places-autocomplete": "^1.3.9",
    "react-native-image-picker": "^0.28.1",
    "react-native-maps": "react-native-community/react-native-maps#master",
    "react-native-maps-directions": "^1.6.0",
    "react-native-onesignal": "^3.2.12",
    "react-native-reanimated": "^1.0.0-alpha.12",
    "react-native-svg": "^9.4.0",
    "react-native-svg-charts": "^5.2.0",
    "react-native-swiper": "^1.5.14",
    "react-native-tab-view": "^2.0.3",
    "react-native-vector-icons": "^6.4.2",
    "react-navigation": "^3.6.0",
    "unstated": "^2.1.1"
  },
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@babel/runtime": "^7.4.2",
    "@react-native-community/eslint-config": "^0.0.3",
    "babel-jest": "^24.5.0",
    "eslint": "^5.15.3",
    "jest": "^24.5.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}
6 Answers

Ciao, this problem is connected to graceful-fs package. Plase, reinstall graceful-fs:

npm install graceful-fs --save-dev

And problem should be solved.

For me, npm cache clean —force was not working, and graceful-fs is not direct dependency in my project.

OS: Ubuntu
Node: 14.6.0 
Npm: 6.14.7

I am still not sure why this error exits, but it works. I found this solution on Flavio Copes's post.

open file /node_modules/graceful-fs/polyfills.js, where the error comes from.

Here’s the function that gives the problem:

function statFix (orig) {
  if (!orig) return orig
  // Older versions of Node erroneously returned signed integers for
  // uid + gid.
  return function (target, cb) {
    return orig.call(fs, target, function (er, stats) {
      if (!stats) return cb.apply(this, arguments)
      if (stats.uid < 0) stats.uid += 0x100000000
      if (stats.gid < 0) stats.gid += 0x100000000
      if (cb) cb.apply(this, arguments)
    })
  }
}

comment out these lines (line 62-64):

// fs.stat = statFix(fs.stat)
// fs.fstat = statFix(fs.fstat)
// fs.lstat = statFix(fs.lstat)

I've run into this problem while trying to start a react-native development server on one of my old projects - (React Native version 0.59.x). For me, the fix was downgrading the node version from 14 to 10 using nvm

Go to C:\Users(your username)\AppData\Roaming Delete npm and npm-cache

Try running again if it gives the error again uninstall and delete Nodejs completely, check that those two files above are still nonexistent and then redownload Nodejs.

On one of my computers the first way worked no problems the second one needed to have Nodejs completely replaced and then worked.

here is the solution for it.

Option 1: Follow this directory C:\Users(your username)\AppData\Roaming Delete the npm folder and if there is one mom cache folder. Run npm clean cache —force ( — force is now required to clean cache) You should be good now if not do option 2.

Option 2: Follow this directory C:\Users(your username)\AppData\Roaming Delete the npm folder and if there is one mom cache folder. Run npm clean cache —force ( — force is now required to clean cache) Make sure everything to do with Nodejs is deleted and uninstalled. Reinstall Nodejs. You should be good now

I had to use node 12.3.1 and npm 6.9.0 to fix this error

nvm use 12.3.1

This installed both. npm install working again.

Related