0

我刚刚将新的 Polymerfire<firebase-app>元素添加到我的 (Polymer 1.x + Firebase 3.x) 项目中,它使项目崩溃了。我希望在 localhost 上看到主屏幕加载,但相反,我只是得到一个空白屏幕和控制台错误。

我的元素.html
<firebase-app auth-domain="my-app-id.firebaseapp.com"
              database-url="https://my-app-id.firebaseio.com/"
              api-key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
</firebase-app>

控制台日志报告以下错误:

控制台日志

firebase-app.html:94
Uncaught ReferenceError: firebase is not defined

相关的代码行(第 94 行)如下:

firebase-app.html,第 94 行
firebase.initializeApp.apply(firebase, init); // Line 94, highlighted error

firebase-app 元素的完整源代码位于此处

https://github.com/firebase/polymerfire/blob/master/firebase-app.html
<!--
@license
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://github.com/firebase/polymerfire/blob/master/LICENSE
-->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="firebase.html">
<dom-module id="firebase-app">
  <script>
    (function() {
      'use strict';
      /**
       * The firebase-app element is used for initializing and configuring your
       * connection to firebase.
       */
      Polymer({
        is: 'firebase-app',
        properties: {
          /**
           * The name of your app. Optional.
           *
           * You can use this with the `appName` property of other Polymerfire elements
           * in order to use multiple firebase configurations on a page at once.
           * In that case the name is used as a key to lookup the configuration.
           */
          name: {
            type: String,
            value: ''
          },
          /**
           * Your API key.
           *
           * Get this from the Auth > Web Setup panel of the new
           * Firebase Console at https://console.firebase.google.com
           *
           * It looks like this: 'AIzaSyDTP-eiQezleFsV2WddFBAhF_WEzx_8v_g'
           */
          apiKey: {
            type: String
          },
          /**
           * The domain name to authenticate with.
           *
           * The same as your Firebase Hosting subdomain or custom domain.
           * Available on the Firebase Console.
           *
           * For example: 'polymerfire-test.firebaseapp.com'
           */
          authDomain: {
            type: String
          },
          /**
           * The URL of your Firebase Realtime Database. You can find this
           * URL in the Database panel of the Firebase Console.
           * Available on the Firebase Console.
           *
           * For example: 'https://polymerfire-test.firebaseio.com/'
           */
          databaseUrl: {
            type: String
          },
          /**
           * The Firebase app object constructed from the other fields of
           * this element.
           */
          app: {
            type: Object,
            notify: true,
            computed: '__computeApp(name, apiKey, authDomain, databaseUrl)'
          }
        },
        __computeApp: function(name, apiKey, authDomain, databaseUrl) {
          if (apiKey && authDomain && databaseUrl) {
            var init = [{
              apiKey: apiKey,
              authDomain: authDomain,
              databaseURL: databaseUrl
            }];
            if (name) {
              init.push(name);
            }
            firebase.initializeApp.apply(firebase, init);
          } else {
            return null;
          }
          return firebase.app(name);
        }
      });
    })();
  </script>
</dom-module>
4

1 回答 1

1

评论摘要:@Bogdan.Nourescu 是正确的。我没有正确安装 firebase-sdk 目录。

我必须使用以下命令使用 Bower 安装 Polymerfire 依赖项:

bower install --save firebase/polymerfire

注意:bower install --save polymerfire指向现在已过时的 DivShot 版本。

于 2016-06-07T23:22:27.747 回答