TypeError:cb.apply不是函数 [英] TypeError: cb.apply is not a function

查看:155
本文介绍了TypeError:cb.apply不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个使用Metro Bundler的现有React Native项目.我的操作系统是Ubuntu 20.04,并且我尝试在物理Android设备和我使用Android Studio创建的Android模拟器上运行该应用程序.

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.

我已经成功克隆了项目的存储库,安装了其依赖项( yarn ),构建了应用程序( react-native run-android ),并在我的计算机上打开了该应用程序手机和模拟器.但是,运行 react-native start 错误指出 TypeError:cb.apply不是函数.这是运行 react-native start 时得到的全部信息和错误:

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)

安装 graceful-fs (关于同一问题,由另一篇帖子推荐)不会什么都没改变,我仍然遇到同样的错误.

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.

推荐答案

我在CI上有一个非常相似的问题,但它在我的本地计算机(节点13)上正常工作.在CI中,当使用我两个月前已经发布的代码在CircleCI或AppCenter上构建项目时,它将引发以下错误.只是没有意义,就像节点已经动态断开一样.

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.

我在节点10、12和14上测试了相同的代码,但现在它仅在节点10(10.22.0)下工作.

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

我遇到的错误:

/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

更新

解决我问题的方法是在 package.json 中添加一个分辨率,以不允许任何lib使用"4.2.4"之前的graceful-fs版本.现在它可以再次与节点12一起使用.

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:不要忘记运行 yarn npm run install 来更新您的 .lock .如果此解决方案不适合您,请对此与此相关的线程添加评论节点12.18.3上的问题

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"
  },

这篇关于TypeError:cb.apply不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆