Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: cb.apply is not a function

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? Thanks in advance.

like image 533
Giorgio Avatar asked Aug 02 '20 10:08

Giorgio


Video Answer


2 Answers

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"   }, 
like image 56
Roni Castro Avatar answered Oct 09 '22 10:10

Roni Castro


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.

like image 30
Bernard Avatar answered Oct 09 '22 10:10

Bernard