angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Cannot find namespace 'firebase'.

Open doczoidberg opened this issue 10 years ago • 100 comments

With the new angularfire I get the error

ERROR in C:\temp\aspnetu\node_modules\angularfire2\database\database.d.ts
(9,29): error TS2503: Cannot find namespace 'firebase'.
ERROR in C:\temp\aspnetu\node_modules\angularfire2\database\database.d.ts
(10,31): error TS2503: Cannot find namespace 'firebase'.
ERROR in C:\temp\aspnetu\node_modules\angularfire2\utils\firebase_object_factory.d.ts
(4,76): error TS2503: Cannot find namespace 'firebase'.
ERROR in C:\temp\aspnetu\node_modules\angularfire2\utils\firebase_list_factory.d.ts
(5,74): error TS2503: Cannot find namespace 'firebase'.
...etc

doczoidberg avatar Jun 17 '16 08:06 doczoidberg

Can you tell me what the solution was for this?

LanderBeeuwsaert avatar Jun 17 '16 10:06 LanderBeeuwsaert

no solution, but I think the issue has nothing to do with Angularfire2 but with my project template with AngularUniversal and HMR: https://github.com/aspnet/JavaScriptServices/issues/140

Update: Steve said, that it is a firebase issue. therefore I reopened the issue

doczoidberg avatar Jun 17 '16 11:06 doczoidberg

Anyone else got the solution for this? I am trying to get angularfire2 working with the 3 SDk.

I have ran

typings install --save --ambient firebase

But I still get this error. I am running this on webpack

joaogarin avatar Jun 22 '16 07:06 joaogarin

Using the definitely typed version for the typings did not help also. Still getting the same error.

joaogarin avatar Jun 22 '16 08:06 joaogarin

I am using angularfire2 in an ionic 2 project and I was getting the same error.

Typings for firebase 3 seem not to be available yet so it doesn't help to install the firebase typings from the global repository.

For me, it helped to include the typings from node_modules/angularfire2 into the typings/main.d.ts file:

/// <reference path="../node_modules/angularfire2/firebase3.d.ts" />

andyfo avatar Jun 22 '16 08:06 andyfo

Yeah, I added it to the tsconfig file in files as mentioned in https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md#3-include-firebase-sdk-typings but I still get that error.

joaogarin avatar Jun 22 '16 09:06 joaogarin

I noticed that after the inclusion of firebase3 my error is actually :

Cannot find name 'Firebase'.

And not 'namespace'. Will keep digging

joaogarin avatar Jun 22 '16 09:06 joaogarin

Hey also getting this problem :/

idesignpixels avatar Jun 22 '16 10:06 idesignpixels

As temporary workaround you can use this type definitions: https://gist.githubusercontent.com/cdcarson/28399c50b02bf6c507fbf5b7b30daa31/raw/fa089d231ca4253d4715f8161efc6af74c972dfa/firebase-sdk-3-typings.d.ts

Add into 'typings.json' into globalDependencies this record: "firebase": "https://gist.githubusercontent.com/cdcarson/28399c50b02bf6c507fbf5b7b30daa31/raw/fa089d231ca4253d4715f8161efc6af74c972dfa/firebase-sdk-3-typings.d.ts" and then typings i

olostan avatar Jun 22 '16 10:06 olostan

In my case I need to get a hold of Firebase() so that I can use https://www.firebase.com/docs/web/api/firebase/authwithcustomtoken.html

authentication with custom tokens. I included the firebase typings but it seems Firebase global is somehow not exposed and typescript complains..

joaogarin avatar Jun 22 '16 12:06 joaogarin

Okay. Regarding the error : Cannot find name 'Firebase'.

Firebase global does not exist anymore, so I still had some parts from the 2 SDK where I was doing new Firebase() which now does not exist.so not an issue..

The namespace thing I managed to get across by adding the right typings as mentioned earlier. either by adding it to your tsconfig as described in https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md#3-include-firebase-sdk-typings or via typings (temporarily by the gist given by @olostan for example)

joaogarin avatar Jun 22 '16 13:06 joaogarin

after installing the typings via gist or docs I still get the error. The only fix for me was to change the change the "files" path in tsconfig.json from "../node_modules/angularfire2/firebase3.d.ts" -> "firebase3.d.ts" and copy firebase3.d.ts into my src directory.

I'm not sure why since using "../typings/globals/firebase/index.d.ts" fixed "Cannot find name 'Firebase'" on FB2 version of exact same app.

easierbycode avatar Jun 22 '16 17:06 easierbycode

Hey all, I'm running into similar issues getting this installed in an Ionic2 project. The tsconfig file has some globbing rules that excludes node_modules/ stuff and I think that may be overriding the manual file entry for the firebase typings. Would be great to be able to simply install them from typings or something equivalent.

alexweber avatar Jun 23 '16 12:06 alexweber

Yes if the tsconfig is excluding the node_modules then you want to add it to the typings.json file. In that case you can do what suggested by @olostan and do :

Add into 'typings.json' into globalDependencies this record: "firebase": "https://gist.githubusercontent.com/cdcarson/28399c50b02bf6c507fbf5b7b30daa31/raw/fa089d231ca4253d4715f8161efc6af74c972dfa/firebase-sdk-3-typings.d.ts" and then typings i

joaogarin avatar Jun 23 '16 12:06 joaogarin

@joaogarin Thanks!

alexweber avatar Jun 23 '16 13:06 alexweber

No problem.

joaogarin avatar Jun 23 '16 13:06 joaogarin

I followed what was suggested by @olostan however, I am still receiving the error TS2304 cannot find name Firebase. any other suggestions or causes as to why this is persisting?

starkiron avatar Jun 24 '16 01:06 starkiron

tried install typings dt~firebase --global --save and it installed firebase 2.4 and the error in the editor was removed but when compiled, I still got the cannot find name Firebase error.

starkiron avatar Jun 24 '16 02:06 starkiron

Still causing me problems with ionic tried lots of things to work around.

idesignpixels avatar Jun 27 '16 10:06 idesignpixels

I solve this problem for my Ionic2 project by doing:

Step 1: package.json to contain the following versions

"dependencies": {
  "angularfire2": "^2.0.0-beta.2",
  "firebase": "^3.0.5",
  ...
},
"devDependencies": {
  "ionic-gulp-browserify-typescript": "^2.0.0", (Dunno what you can do for non-Ionic projects)
  ...

Step 2: install typings version 1.0.5 (that might be due to node version i have - v5.12.0)

Step 3: tsconfig.json to contain:

 "files": [
    "node_modules/angularfire2/firebase3.d.ts"
  ],
  "exclude": [
    "node_modules",
    "typings/global",
    "typings/global.d.ts"
  ],

Step 4: typings/index.d.ts

/// <reference path="globals/es6-shim/index.d.ts" />
/// <reference path="../node_modules/angularfire2/firebase3.d.ts" />

fincefid avatar Jun 27 '16 10:06 fincefid