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

The solution is using the "files" array in the tsconfig.json file.

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

This is stated in the installation and setup section.

davideast avatar Jun 27 '16 16:06 davideast

Here's an alternative to fincefid's and davideast's solutions above because

the "files" property cannot be used in conjunction with the "exclude" property 1

which might be problematic for some setups. This worked for me with an Ionic v2 project.

Instead of modifying tsconfig.json, you can reference the Firebase 3 typings file that is included in the angularfire2 node package directly in your typings.json. Run:

  • typings install file:node_modules/angularfire2/firebase3.d.ts --save --global
    • this saves the reference into typings.json
    • NOTE: requires typings v.1+
  • typings install
    • this puts the typings files in the typings/ directory.

filoxo avatar Jun 30 '16 05:06 filoxo

@filoxo did not know you can install typings directly from the node_modules like that :+1:

dmastag avatar Jul 01 '16 05:07 dmastag

Hi everyone, Sorry to re-open the discussion... I followed the doc and your advice but I am still facing the same error "Cannot find namespace 'firebase'" when I try to build my Angular 2 web app. I use Angular CLI. I referenced "node_modules/angularfire2/firebase3.d.ts" in the files array property of tsconfig.json as @davideast suggested... Please can somebody help me ? Thanks

VTordjman avatar Jul 12 '16 18:07 VTordjman

Instead of using node_modules/angularfire2/firebase3.d.ts that came with angularfire2, I did typings install firebase to install the one from https://github.com/typed-typings/npm-firebase. That one worked for me and I was able to do import * as firebase from 'firebase';. I really don't know why. They should be the same.

5amfung avatar Jul 12 '16 18:07 5amfung

Thanks @5amfung it works !

VTordjman avatar Jul 12 '16 19:07 VTordjman

typings install firebase installs the types as a module that must be installed, which is correct (as far as I know) for the latest firebase JS library.

The AngularFire2 library still expects the firebase types to be global (ambient) which is why in the docs it suggests typings install firebase --ambient --save (or typings install firebase --global --save).

Since the new firebase typings are marked as modules then you cannot install them globally. I found that the best trick is to use the trick by @filoxo in https://github.com/angular/angularfire2/issues/234#issuecomment-229560239

petebacondarwin avatar Jul 18 '16 19:07 petebacondarwin

This error is still present, none of the solution above worked for me.

IvRRimum avatar Aug 30 '16 18:08 IvRRimum

@IvRRimum Try updating to the latest versions of angularfire2, firebase, angular (RC5), and angular-cli. I have been using this setup without any issues.

5amfung avatar Aug 30 '16 19:08 5amfung

I find that you can add "types": [ "jasmine", "firebase" ] to tsconfig.json

l3abyl3oy avatar Sep 02 '16 18:09 l3abyl3oy

@davideast where in the installation and setup section does it mention that?

@IvRRimum How do you check / update the versions of each of those?

simonbromberg avatar Sep 04 '16 02:09 simonbromberg

As for me, I followed what was suggested by @olostan and it worked for me

OyebisiJemil avatar Sep 08 '16 21:09 OyebisiJemil

I'm having the same error. Please provide complete installation steps in readme. This is very confusing. 😕 😫

hirenchauhan2 avatar Sep 24 '16 12:09 hirenchauhan2

@harry008 https://github.com/r-park/todo-angular2-firebase This repo works. Take this and delete stuff you don't need.

IvRRimum avatar Sep 24 '16 18:09 IvRRimum

Solved my issue by following steps 👇

  • Added 👉 /// <reference path="../node_modules/firebase/firebase.d.ts" /> to src/typings.d.ts
  • Added "files": [ "../node_modules/firebase/firebase.d.ts" ] to and removed "types": ["firebase"] from src/tsconfig.json as it gives error of Could not find definitions for file 'firebase'. You can keep types array for other things.

I've spent my half day just for this 😫 😓
@davideast I hope you had enjoyed your [pre/post/mid][whatever] ☕ in that meantime 😃

hirenchauhan2 avatar Sep 24 '16 18:09 hirenchauhan2

@IvRRimum I figured out that while hovering to https://github.com/unseen1980/Angular2-Firebase-Auth

hirenchauhan2 avatar Sep 24 '16 18:09 hirenchauhan2

There is so much BS going on with this implementation, and none of the above suggestion worked for me loading alternative options...................

Emmanuel-Mariki avatar Sep 25 '16 00:09 Emmanuel-Mariki

I'm having problems too. I followed the steps by @harry008 , but I'm still getting errors about firebase.d.ts when I try ng serve:

ERROR in [default] /Users/jim/Git-Projects/Park-Boys-Bootcamp/4-Firebase-Rooms/project/node_modules/firebase/firebase.d.ts:391:2 
Duplicate identifier 'export='.

ERROR in [default] /Users/jim/Git-Projects/Park-Boys-Bootcamp/4-Firebase-Rooms/project/src/typings.d.ts:6:10 
';' expected.

ERROR in [default] /Users/jim/Git-Projects/Park-Boys-Bootcamp/4-Firebase-Rooms/project/src/typings/modules/firebase/index.d.ts:498:0 
Duplicate identifier 'export='.

JimLynchCodes avatar Sep 25 '16 12:09 JimLynchCodes

@JimTheMan looks like you have installed typings for firebase via typings install firebase or something like that. I guess that are conflicting with the referenced typings file in tsconfig.json. Try removing the firebase from typings folder and check if its working or not.

hirenchauhan2 avatar Sep 27 '16 17:09 hirenchauhan2

Thanks @harry008 you can check here: https://github.com/ParkBoys/Park-Boys-Bootcamp/tree/master/4-Firebase-Rooms/project

I have removed everything from the typings.d.ts file and am still getting the errors:

src_ -bash _110x24

JimLynchCodes avatar Sep 28 '16 00:09 JimLynchCodes