14

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/"
    ]
  }
}
Yehya
  • 506
  • 1
  • 5
  • 16

6 Answers6

34

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

npm install graceful-fs --save-dev

And problem should be solved.

Giovanni Esposito
  • 10,696
  • 1
  • 14
  • 30
  • 6
    I don't have any direct dependency on graceful-fs. I tried to install graceful-fs as well, but still the same error. – Yehya Jul 23 '20 at 13:04
  • Ciao, can you show me your project dependencies please? Thanks – Giovanni Esposito Jul 23 '20 at 13:08
  • I have edited the description and pasted my package.json file there. Thanks for your time. – Yehya Jul 23 '20 at 15:52
  • Ciao, seems that I'm repeting myself but I try to explain. Jest has a dependency with graceful-fs. Try to install graceful-fs as dependency like I wrote in my answer editated. Should solve – Giovanni Esposito Jul 23 '20 at 16:17
  • Thank you for your help. At the end, I had to clean everything including node, npm cache and clone again from the repo. But this library was required too, even though I tried to add it before as well but only worked when I cleared up everything. – Yehya Jul 30 '20 at 09:21
  • 6
    Well done! I'm happy to ear that. These problems annoying you for hours and hours and when you solve you are so tired that you can't almost coding anymore. Now relax, a cup of coffee and then restart to coding :) Have a nice day! – Giovanni Esposito Jul 30 '20 at 09:31
13

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)
Kirk Hammett
  • 656
  • 8
  • 24
Madan Bhandari
  • 2,094
  • 2
  • 26
  • 46
  • This is a poor solution because it wouldn't work on a CI/CD system, for example, and every user that would download your project would have to change this to build the project. It's better to strive for builds with dependencies that works together. – simeg Dec 19 '20 at 12:11
  • FWIW, This seems to be the only solution that works for me. All instance of graceful-fs are at 4.2.10, which should suffice. I've force-cleaned the cache multiple times, changed versions of Node (though using older versions of Node is not an option), and tried deleting and re-installing the node_modules each time. You're right this is not a commitible solution. However it works well if you need it for a one-shot fix (in my case, it's for running ember-update-cli --run-code-mods) – blackstrype Jan 05 '23 at 10:07
9

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

Kacper Wiszczuk
  • 1,809
  • 11
  • 14
5

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.

  • Thankyou for reply. I had to clean up everything like you suggested but it also required that I install graceful-fs library. Only then it worked. – Yehya Jul 30 '20 at 09:22
0

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

ABHIJEET KHIRE
  • 2,037
  • 17
  • 10
  • option 2: worked. I used the default node+npm that came with Nodist. And I am running npm on Windows 7. – rubens Jul 31 '20 at 15:49
0

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.

Dazzle
  • 2,880
  • 3
  • 25
  • 52