FirebaseExtended / angularfire

AngularJS bindings for Firebase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

angular.js: ReferenceError: firebase is not defined

JimLynchCodes opened this issue · comments

commented

Hello,

I'm using AngularJS 1.4, and I'm trying to use the storage functionality in firebase. It seems that the storage was never added as an Angular service. :(

Others have told me to just do, import * as firebase from 'firebase', but this gives me the error, "ReferenceError: firebase is not defined".

I'm not using typescript or requirejs. I'm just using regular gulp, bower, npm. How can I access this 'firebase' global variable?

Thanks.

Btw- repo is here: https://github.com/ng-nj/ng-nj.org/

Hi @JimTheMan,
it depends on the design of your app and
where do you initialize your firebaseApp.

Here is one of my "AngularJS & Firebase" projects: https://github.com/IagoBarboza/firechat
Take a look on firebase-initialization.js and index.html

Hope it helps!

commented

Hey thanks. I see your firebase-initialization.js file, but I don't understand how you are not getting a firebase is not defined error.

commented

You aren't using require or anything. For me it doesn't see a global firebase variable. :(

Where are you initializing your firebaseApp?

On your main.controller.js file, you are initializing the firebaseApp inside a function,
then you have a local object being initialized.

Try to move:
var config = {
apiKey: "AIzaSyAWJp_C_eqNpQaPZsmKxIYzUOg5QgkNTTM",
authDomain: "ng-nj.firebaseapp.com",
databaseURL: "https://ng-nj.firebaseio.com",
storageBucket: "project-537738856427405277.appspot.com",
messagingSenderId: "964546155082"
};

firebase.initializeApp(config);

to an specific file.js without (function(){}()) and then, include this js file in your index.html
Doing this you probably will be able to access the firebase instance from any
point of your app.

Very odd. On one computer it works for me, but the exact same code another another gives, "firebase is not defined" error...

Closing as invalid since this doesn't follow the issue template.

@JimTheMan - Is this any different from #856? Also, please follow the issue template. This issue as it stands does not meet the bar for what we need to help you debug properly. We really need to know what version of the Firebase SDK you are using for starters. And a repro the size of https://github.com/ng-nj/ng-nj.org/ is not reasonable for us to debug every time someone comes along with a usage question. Please open a new issue, follow the issue template, and include a minimal repro using something like JSFiddle or Plunker.

Yes it is different. #856 was about it not having a .storage() method on the $firebase service.

This is a completely different error about "firebase not defined" error.

I can't understand what you mean by, "every time someone comes along with a usage question". The code is plainly there int he repo with package.json and bower.json files.

I can reproduce the error by putting that initialization code in index.module. It seems to work thought when I put it in a controller or index.config.js module block.

Hey there. Apologies for my previous response. I just re-read it and it was pretty combative. I responded at a time when I was upset about something else which is never a good idea for a maintainer. Let's see if I can re-set the discussion.

First question: Are @JimTheMan and @HomeboxJim the same person? This conversation kind of suggests you are, but it would help my head if you make that clear.

Issue #856 ended up evolving into a question about how to access the global firebase (which is what this issue is for) and this comment made me think @JimTheMan got it worked out. That's why I am confused.

Regarding your repro: I'm sure it does in fact show you have an issue, but it is far from a minimal repro (mcve in Stack Overflow terms). We get a ridiculous amount of support requests just like this every day through our different support channels and we cannot spend ten minutes digging through repos like the one you sent to see where things are going wrong. It simply doesn't scale. If you can remove parts from your repro piece by piece until you have a minimal, failing repro, that is something we can manage. I would suggest trying to make it a live repro via JSFiddle or Plunker too to get an even higher chance of us being able to debug it.

Lastly regarding our issue template: we get a lot of issues opened up on this repo. There are a lot without any details whatsoever to help us resolve the issue. Simple things like what Firebase version people are using are not included (in fact, you still haven't told me which version you are using). You intentionally deleted the issue template when making this issue. That means you probably didn't read the info it contained and this issue is invalid. You should open up a new issue which follows the issue template and provides the info it requires. That would save you and I a lot of work and should result in us resolving your issue satisfactorily.

commented

Thanks. It was just a generic question about how one is supposed to get access to the global firebase variable in an AngularJs project and how to prevent it from saying, "ReferenceError: firebase is not defined". But it's using firebase: 2.4.1 and angularfire: 1.1.4

There is no github repo for firebase so I figured this qas the best place to ask about AngularJS with firebase.

I will try your suggestion later tonight @HomeboxJim. Thanks.

commented

@HomeboxJim I don't know how you are getting it to work. It gives me errors no matter where in my project I put it:

ngnjorg

commented

Very weird. I was able to get past the little f "firebase is not defined" error only when I upgrade to firebase library 3.4.1, but then I have a bunch of big F "Firebase is not defined" errors. Lol

Locking the conversation on this thread. I've given you ample time and suggestions on what to do to get a resolution here. Please open up a new issue and follow the issue template and you'll get some help.

Also, I have no idea why you are talking to @HomeboxJim when you are that same person:

screen shot 2016-10-06 at 1 54 10 pm