Basic usage of @react-native-firebase/admob gives: "TypeError: (0, _admob.default) is not a function". Is it deprecated? or Why doesnt work?

Basic usage of @react-native-firebase/admob gives: "TypeError: (0, _admob.default) is not a function". Is it deprecated? or Why doesnt work?

是否弃用了@react-native-firebase/admob?或者只是.. 为什么它不起作用?

我正在使用@react-native-firebase/admob (https://rnfb-docs.netlify.app/admob/usage)。 在使用“admob()”之前一切正常。当我将 admob() 添加到代码时出现此错误:

“TypeError: (0, _admob.default) 不是一个函数”

有人知道为什么吗?

我的代码如下(基本用法):

import React from 'react';
import { Text, View} from 'react-native';
import admob, { MaxAdContentRating } from '@react-native-firebase/admob';
import { InterstitialAd, RewardedAd, BannerAd, TestIds } from '@react-native- 
firebase/admob';
import { BannerAdSize} from '@react-native-firebase/admob';



class App extends React.Component{

componentDidMount(){

// this was taked of official page: https://rnfb-docs.netlify.app/admob/usage#installation
admob()
  .setRequestConfiguration({
    // Update all future requests suitable for parental guidance
    maxAdContentRating: MaxAdContentRating.PG,

    // Indicates that you want your content treated as child-directed for purposes of COPPA.
    tagForChildDirectedTreatment: true,

    // Indicates that you want the ad request to be handled in a
    // manner suitable for users under the age of consent.
    tagForUnderAgeOfConsent: true,
  })
  .then(() => {
    // Request config successfully set!
  });
 }
render(){
return(
  <View style={{
    alignItems:"center", 
    justifyContent:"center",
    height:"100%"}}>
    <Text style={{color:"black"}}>
      Hola
    </Text>
    <BannerAd 
      unitId={TestIds.BANNER} 
      size={BannerAdSize.FULL_BANNER} />
  </View>
  )
 }
}
 export default App;


   

为了完成您的搜索,我将补充一点,Admob 已从 React Native Firebase 中删除,并且没有计划再次实现它。仅在外部存储库上重新托管代码。 最后支持的版本是 11.5.0

这意味着如果您想在重新托管之前使用 RN Firebase Admob,则需要在此版本中使用所有其他服务(如 RNF 分析)。

更多信息请查看https://github.com/invertase/react-native-firebase/issues/5329#issuecomment-843272057

记得用

dependencies{
   "@react-native-firebase/admob": "11.5.0",
   "@react-native-firebase/app": "11.5.0",
 }

而不是

dependencies{
   "@react-native-firebase/admob": "^11.5.0",
   "@react-native-firebase/app": "^11.5.0",

 }```

我能解决。

已解决

只需在文件“package.json”中检查 firebase 包是否具有相同的版本,例如:

dependencies{
   "@react-native-firebase/admob": "^11.5.0",
   "@react-native-firebase/app": "^11.5.0"
}

提示

解决类似错误。

尽管有@CodeJoe 的回答,我仍然对周围的 React Native Firebase 的不同文档感到困惑,因此我花了很多时间和精力来解决它。

我打开了一个问题 here,确认 Google 从 v11.5.0 开始删除了 AdMob 包。

AdMob is no longer in Firebase APIs, so this module no longer wraps it, there is no documentation to correct. However it did exist as recently as v11.5.0 here and if you browse the repository at that point, you may consider the e2e tests for AdMob at the time a primer on "How To Use AdMob" https://github.com/invertase/react-native-firebase/tree/0217bff5cbbf233d7915efb4dbbdfe00e82dff23/packages/admob/e2e


请不要像我一样检查正确的文档和网站:

正确

https://rnfirebase.io

错错错了,这个指的是旧版本

https://rnfb-docs.netlify.app


The internet has a long memory, so there are stale copies of the docs out and about yes, but rnfirebase.io is always the official and current doc site

Admob 已被 Google 从 firebase 生态系统中完全删除,因此它不存在于此。它有一些社区包,我们的 v11.5 版本有它,我们希望剥离我们的实现并为社区更新它,但这需要时间,不幸的是我们仍然积压在官方 firebase api 上,所以它还没有还没发生


因此,对于 AdMob 解决方案,我会使用另一个库,并将 react-native-firebase 用于他们目前提供的解决方案

替代库(2021 年 8 月)

免责声明

  • React Native Firebase 对于他们提供的其他包(Firebase、Analitycs...)仍然是一个很棒的库,Admob 11.5 版仍然是一个解决方案。这些只是 Admob 替代品的建议。

我可以在 React Native 0.65.1 中为我的 RewardedAds 使用 11.5.0 降级技巧。我如上所述编辑了 package.json 文件。它没有用,但我设法 运行 它以不同的方式:

  1. 关闭所有 运行ning react-native 相关终端。卸载@react-native-firebase/app.

    npm 卸载@react-native-firebase/app

  2. 直接用这个命令安装@react-native-firebase/app版本11.5.0。

    npm 安装@react-native-firebase/app@11.5.0

  3. 安装后,转到 package.json>dependencies 并使两个包版本相同 (11.5.0) 并删除 ^.

    "@react-native-firebase/admob": "11.5.0",

    "@react-native-firebase/app": "11.5.0",

  4. 使用新缓存启动 react-native 然后 运行-android.

    npx react-native start --reset-cache

    npx react-native 运行-android