类型错误:cb.apply 不是函数

Gio*_*gio 35 android react-native metro-bundler

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

我已经成功克隆了项目的 repo,安装了它的依赖项 ( yarn),构建了应用程序 ( react-native run-android),并在我的手机和模拟器上打开了应用程序。但是,运行react-native start错误说TypeError: cb.apply is not a function. 这是我在运行时得到的完整信息和错误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)

Run Code Online (Sandbox Code Playgroud)

安装graceful-fs(正如另一篇关于同一问题的帖子所推荐的)不会改变任何东西,我仍然遇到同样的错误。

这里可能是什么问题?提前致谢。

Ron*_*tro 52

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

我用节点 10、12 和 14 测试了相同的代码,但现在它只适用于节点 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
Run Code Online (Sandbox Code Playgroud)

更新

解决我的问题是添加一个决议,package.json不允许任何库使用“4.2.4”之前的优雅-fs版本。现在它再次与节点 12 一起工作。

PS:不要忘记运行yarnnpm run install更新您的.lock. 如果此解决方案对您不起作用,请在与 Node 12.18.3 上的此问题相关的线程中添加评论

  "devDependencies": {
    ...
  },
  "resolutions": {
    "graceful-fs": "4.2.4"
  },
Run Code Online (Sandbox Code Playgroud)

  • 天哪,我喜欢这个答案,你的更新救了我。几个小时以来一直试图解决该问题,尝试了网络上可用的所有其他解决方案,但没有任何效果。谢谢! (2认同)

Ber*_*ard 17

我今天在做构建时也得到了这个。(运行节点 12.8.3)

我重新安装了以下软件包:

npm install graceful-fs --save-dev
Run Code Online (Sandbox Code Playgroud)

这就解决了上述问题。


Har*_*lin 16

这里是 Ubuntu 20.04 用户,节点为 16.0.0。当我运行时,我遇到了同样的错误:

> npx create-react-app [my app]
Run Code Online (Sandbox Code Playgroud)

我发现我必须重新安装create-react-app(首先从node_modules中将其删除)才能解决它。

> npm install create-react-app
Run Code Online (Sandbox Code Playgroud)

  • 啊www是的,谢谢你分享这个。我没有安装它,它没有抱怨该模块不存在,而是显示了问题中的错误。也许你应该拥有它 --save-dev 因为它不是生产所需的依赖项? (2认同)

Bra*_*don 6

如果你安装了 nvm,那就更简单了。要检查这一点,请运行

nvm --version
Run Code Online (Sandbox Code Playgroud)

然后安装最新的 lts 版本的节点,运行

nvm install --lts
Run Code Online (Sandbox Code Playgroud)

这对我有用,如果有帮助,请告诉我


小智 5

我在我的两台电脑上都解决了它。需要做更多的工作。

  • 选项1:

    • 按照这个目录 C:\Users(your username)\AppData\Roaming
    • 删除npm文件夹
    • 如果有一个npm 缓存文件夹。运行npm clean cache -force,或npm cache clean -force在 Windows 上(——现在需要强制清理缓存)
    • 如果不做选项 2,你现在应该很好。
  • 选项 2:

    • 按照这个目录 C:\Users(your username)\AppData\Roaming
    • 删除npm文件夹
    • 如果有一个npm 缓存文件夹。npm clean cache -force在 linux 或npm cache cleanwindows上运行(——现在需要强制清理缓存)
    • 确保删除与 Nodejs 相关的所有内容
    • 并卸载了 NodeJS。
    • 重新安装 Node.js。
    • 你现在应该很好。