Javascript 未捕获的 ReferenceError:Firebase 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34968284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught ReferenceError: Firebase is not defined
提问by Eddev
I am trying to follow the tutorial on designing a database in firebase, but I am getting the following error in the JavaScript console:
我正在尝试按照有关在 firebase 中设计数据库的教程进行操作,但在 JavaScript 控制台中出现以下错误:
Uncaught ReferenceError: Firebase is not defined
未捕获的 ReferenceError:Firebase 未定义
Here is the link to the tutorial, and the code snippet that I was trying to run in the JavaScript console is: https://www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html
这是教程的链接,我试图在 JavaScript 控制台中运行的代码片段是:https: //www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild("height").on("child_added", function(snapshot) {
console.log(snapshot.key() + " was " + snapshot.val().height + " meters tall");
});
采纳答案by Eddev
In the heading, include the following:
在标题中,包括以下内容:
<head>
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<link rel='stylesheet' type='text/css' href='/resources/tutorial/css/example.css'>
</head>
That'll solve the problem.
这样问题就解决了。
回答by guy mograbi
There is a guide on how to migrate to the new version.
You can find it at: https://firebase.google.com/support/guides/firebase-web
有一个关于如何迁移到新版本的指南。
您可以在以下位置找到它:https: //firebase.google.com/support/guides/firebase-web
And here is the relevant snippet for you
这是您的相关片段
回答by Rodrigo
I had the same issue when installed firebase via "ionic add firebase". This added firebase version 3.2.0. Then, while looking for answers I tried the cdn with version 2.4.2 and the error disappeared, so I figured out the version downloaded via ionic was what caused the error, so I downloaded the 2.4.2 version and now it works.
通过“ionic add firebase”安装firebase时,我遇到了同样的问题。这增加了 firebase 版本 3.2.0。然后,在寻找答案时,我尝试了 2.4.2 版的 cdn,错误消失了,所以我发现通过 ionic 下载的版本是导致错误的原因,所以我下载了 2.4.2 版,现在它可以工作了。
Hope this helps.
希望这可以帮助。
回答by Alberto Hernández
i have the issue with firebase.util lib, as Rodrigo said i think is problem of the versión.
我有 firebase.util lib 的问题,正如 Rodrigo 所说,我认为是版本的问题。
Before:
前:
var ref = new Firebase('url');
Now:
现在:
firebase.initializeApp(config);
As the firebase object is defined differently it does not find it. In my case, I need to update the library to be compatible with version 3.0 of firebase. I do not think it's a good idea to use the old library, to get out of step is fine but will have to update the codes to version 3. If no one has done yet may be our opportunity to contribute to the community.
由于 firebase 对象的定义不同,它找不到它。就我而言,我需要更新库以与 firebase 3.0 版兼容。我认为使用旧库不是一个好主意,不合时宜是好的,但必须将代码更新到版本 3。如果还没有人这样做,可能是我们为社区做出贡献的机会。
回答by j22purikas
<head>
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<link rel='stylesheet' type='text/css' href='/resources/tutorial/css/example.css'>
</head>
回答by sangram desai
create the connection variable from the firebase.
从 Firebase 创建连接变量。
con = {
"apiKey": "your key",
"authDomain": "example.firebaseapp.com",
"databaseURL": "https://example.firebaseio.com/",
"projectId": "example",
"storageBucket": "example.appspot.com",
"messagingSenderId": "id"
};
initialize the firebase using this
使用这个初始化firebase
firebase.initializeApp(con);
回答by brownmagik352
If you are using Firebase Hosting like I was (and using <script src="/__/firebase/7.14.5/firebase-app.js"></script>
), then you will run into this error if you try to test locally without running firebase serve
.
如果您像我一样使用 Firebase Hosting(并使用<script src="/__/firebase/7.14.5/firebase-app.js"></script>
),那么如果您尝试在本地测试而不运行firebase serve
.