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

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)