Firebase 远程配置:未捕获的类型错误:firebase.remoteConfig 不是函数

Has*_*san 3 firebase firebase-remote-config

我正在尝试使用 Firebase 远程配置。我遵循 firebase docs 进行此设置https://firebase.google.com/docs/remote-config/use-config-web#add-remote-config-to-your-app。但是我收到了这个错误 Uncaught TypeError: firebase.remoteConfig is not a function。

我在这里做什么:

index.html 文件

    	<!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src="https://www.gstatic.com/firebasejs/7.11.0/firebase-app.js"></script>

    <!-- TODO: Add SDKs for Firebase products that you want to use
         https://firebase.google.com/docs/web/setup#available-libraries -->
    <script src="https://www.gstatic.com/firebasejs/7.11.0/firebase-analytics.js"></script>

    <script>
      // Your web app's Firebase configuration
    var firebaseConfig = {
      apiKey: "api-key",
      authDomain: "project-id.firebaseapp.com",
      databaseURL: "https://project-id.firebaseio.com",
      projectId: "project-id",
      storageBucket: "project-id.appspot.com",
      messagingSenderId: "sender-id",
      appId: "app-id",
      measurementId: "G-measurement-id",
    };
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
      firebase.analytics();
    </script>

<script>
const remoteConfig = firebase.remoteConfig();
remoteConfig.settings = {
  minimumFetchIntervalMillis: 3600000,
};

remoteConfig.defaultConfig = ({
  'test': 'Welcome',
});

console.log(remoteConfig.getasString("test"));
</script
Run Code Online (Sandbox Code Playgroud)

我想我在这一行中得到了这个错误 const remoteConfig = firebase.remoteConfig(); . 提前致谢。

Meh*_*nTM 6

在我的 React 应用程序中,问题是缺少下面的导入语句:

import "firebase/remote-config";
Run Code Online (Sandbox Code Playgroud)


Pet*_*dad 5

在使用远程配置之前,需要添加以下脚本:

<script src="https://www.gstatic.com/firebasejs/7.11.0/firebase-remote-config.js"></script>
Run Code Online (Sandbox Code Playgroud)

请在此处查看有关如何设置的更多信息:

https://firebase.google.com/docs/web/setup