52

I'm trying to run an existing React Native project that uses Metro Bundler. My operating system is Ubuntu 20.04 and I've tried to run the app both on a physical Android device and on an Android simulator that I created with Android Studio.

I have successfully cloned the project's repo, installed its dependencies (yarn), built the app (react-native run-android), and opened the app on my phone and simulator. However, running react-native start errors out saying TypeError: cb.apply is not a function. Here is the full information and errors I get when running react-native start:

$ react-native start
warn Your project is using deprecated "rnpm" config that will stop working from next release. Please use a "react-native.config.js" file to configure the React Native CLI. Migration guide: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
warn The following packages use deprecated "rnpm" config that will stop working from next release:
  - rn-fetch-blob: https://npmjs.com/package/rn-fetch-blob
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  Running Metro Bundler on port 8081.                                         │
│                                                                              │
│  Keep Metro running while developing on any JS projects. Feel free to        │
│  close this tab and run your own Metro instance if you prefer.               │
│                                                                              │
│  https://github.com/facebook/react-native                                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

warn Your project is using deprecated "rnpm" config that will stop working from next release. Please use a "react-native.config.js" file to configure the React Native CLI. Migration guide: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
warn The following packages use deprecated "rnpm" config that will stop working from next release:
  - rn-fetch-blob: https://npmjs.com/package/rn-fetch-blob
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
Looking for JS files in
   /home/ggiuffre/Documents/squib/app 

Loading dependency graph, done.
 BUNDLE  [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1)/home/ggiuffre/Documents/squib/app/node_modules/@react-native-community/cli/node_modules/graceful-fs/polyfills.js:285
        if (cb) cb.apply(this, arguments)
                   ^

TypeError: cb.apply is not a function
    at /home/ggiuffre/Documents/squib/app/node_modules/@react-native-community/cli/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqCallback.oncomplete (fs.js:169:5)

Installing graceful-fs (as recommended by another post about the same problem) doesn't change anything, and I still get the same error.

What could be the issue here?

starball
  • 20,030
  • 7
  • 43
  • 238
Giorgio
  • 2,137
  • 3
  • 20
  • 40

11 Answers11

67

I had a very similar problem on CI, but it works normally on my local machine (Node 13). In the CI, when building the project on CircleCI or on AppCenter with a code that I already released two months ago it throws the error below. It just does not make sense, it's like node had broken dynamically.

I tested the same code with node 10, 12 and 14, but now it works just with node 10 (10.22.0).

The error I had:

/home/circleci/my-app/node_modules/@react-native-community/cli/node_modules/graceful-fs/polyfills.js:285
        if (cb) cb.apply(this, arguments)
                   ^

TypeError: cb.apply is not a function
    at /home/circleci/my-app/node_modules/@react-native-community/cli/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqCallback.oncomplete (fs.js:169:5)

> Task :app:bundleReleaseJsAndAssets FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1

UPDATE

What solved my problem was to add a resolution to the package.json to do not allow any lib to use a version of graceful-fs that is before "4.2.4". Now it works again with node 12.

PS: Don't forget to run yarn or npm run install to update your .lock. If this solution does not work for you, please add a comment to this thread related to this problem on Node 12.18.3

  "devDependencies": {
    ...
  },
  "resolutions": {
    "graceful-fs": "4.2.4"
  },
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Roni Castro
  • 1,968
  • 21
  • 40
  • 3
    OMG I love this answer, your update saved me. Been trying to fix the problem for hours now, tried every other solution available on the web and nothing was working. Thanks! – gbalduzzi Mar 26 '21 at 11:01
25

I got this too today when doing a build. (running node 12.8.3)

I reinstalled the follow package:

npm install graceful-fs --save-dev

This solved the above problem.

Bernard
  • 1,208
  • 8
  • 15
16

An Ubuntu 20.04 user here with node 16.0.0. I was getting the same error when I would run:

> npx create-react-app [my app]

I found that I had to reinstall create-react-app (remove it from node_modules first) to solve it.

> npm install create-react-app
Harlin
  • 1,059
  • 14
  • 18
  • 2
    Ahwww yesss, thank you for sharing this. I did not have it installed, and instead of complaining that the module didn't exist, it was instead showing the error from the question. Maybe you should have it --save-dev as it is not a needed dependency for production? – denNorske Sep 13 '21 at 19:10
  • 1
    Solved my different but related problem, ty for posting. – sammms Jul 19 '22 at 15:59
13

I solved it on both my computers. One needed more work on it.

  • Option 1:

    • Follow this directory C:\Users(your username)\AppData\Roaming
    • Delete the npm folder
    • and if there is one npm cache folder. Run npm clean cache -force, or npm cache clean -force on windows ( — 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 npm cache folder. Run npm clean cache -force on linux, or npm cache clean on windows ( — force is now required to clean cache)
    • Make sure everything to do with Nodejs is deleted
    • and uninstalled NodeJS.
    • Reinstall Nodejs.
    • You should be good now.
Antoine Boisier-Michaud
  • 1,575
  • 2
  • 16
  • 30
9

If you have nvm installed, its even simpler. To check this, run

nvm --version

then to install the latest lts version of node, run

nvm install --lts

That's what worked for me, let me know if that helps

Brandon
  • 178
  • 2
  • 15
4

If you are using Windows 10, I solved this issue by doing the followings:

First, this was the error:

enter image description here

  1. Navigate to %USERPROFILE%\AppData\Roaming\
  2. Remove any cache that may be there by typing Run npm clean cache —force
  3. Remove the NPM Folder
  4. Re-install the Node.js and make sure to include NPM during the installation of Node.js

After the above steps, I am able to run the npm like before and add modules that I needed. enter image description here

William Pourmajidi
  • 967
  • 11
  • 12
2

On Windows:

  1. Goto the path C:/Users/{User}/AppData/Roaming

  2. delete the 2 folders npm npm-cache at path

  3. npm clean cache —force

1

In my case I was trying to use Husky and this error occurs:

husky > commit-msg (node v15.6.0)
npm ERR! cb.apply is not a function

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2021-01-24T06_04_04_218Z-debug.log

>>> Installation [ 'commitlint@latest' ] fail with code 1 <<<

husky > commit-msg hook failed (add --no-verify to bypass)

I run the command below and problem was solved

npm i -D commitlint
btd1337
  • 2,616
  • 2
  • 16
  • 25
1

Your node version is not matching with the libraries/frameworks you are trying to use. Try to update you node version and check.

Better to use nodist/nvm to do upgrade or downgrade with finger snap.

1
    if (cb) cb.apply(this, arguments)
                   ^

TypeError: cb.apply is not a function
    at /home/circleci/my-app/node_modules/@react-native-community/cli/node_modules/graceful-fs/polyfills.js:285:20

For this in pollyfills.js file go to line 62,63,64 and comment those shown below, Worked for me for my Gitbook

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

The problem is occuring because of new npm naming restrictions. Project names can no longer contain capital letters. Rename the directory with lower case letters.

John C
  • 880
  • 10
  • 13