Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/"
    ]
  }
}
like image 777
Yehya Avatar asked Jul 23 '20 12:07

Yehya


2 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.

like image 190
Giovanni Esposito Avatar answered Sep 20 '22 03:09

Giovanni Esposito


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)
like image 25
Madan Bhandari Avatar answered Sep 18 '22 03:09

Madan Bhandari