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

If looking for auth-types, import @firebase/auth-types

import * as firebase from 'firebase'; import { User } from '@firebase/auth-types';

then you can use the firebase user just like this: public user: User;

alx-andru avatar Dec 20 '17 01:12 alx-andru

back to version "firebase": "4.8.0". remember to clear your cache. to check the version use npm list firebase

paulimfavarato avatar Dec 20 '17 08:12 paulimfavarato

This issue just wasted shit tons of our time. I'm sticking with the new Firebase but holy crap getting this working was needlessly shit.

@alx-andru Thanks for the good suggestion. Got me working, although sometimes I have to recompile. Yep, even with your suggestion, I still get this behavior in a very fresh project build with the Angular CLI:

ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2017-12-20T10:00:51.758Z
Hash: 11914b299a7274a699d9
Time: 3134ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.93 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 636 bytes [initial] [rendered]
chunk {scripts} scripts.bundle.js (scripts) 72.7 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 918 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 853 kB [initial] [rendered]

ERROR in node_modules/@firebase/database/dist/esm/src/api/Database.d.ts(4,33): error TS2307: Cannot find module '@firebase/app-types/private'.
node_modules/@firebase/database/dist/esm/src/core/AuthTokenProvider.d.ts(17,39): error TS2307: Cannot find module '@firebase/app-types/private'.
node_modules/angularfire2/auth/auth.d.ts(10,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/auth/auth.d.ts(11,36): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/database.d.ts(7,15): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/database/interfaces.d.ts(3,50): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(3,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(12,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(42,40): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(43,41): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(44,37): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/list/audit-trail.d.ts(7,133): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/database/list/state-changes.d.ts(6,135): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/database/list/state-changes.d.ts(7,113): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/firebase.app.module.d.ts(5,45): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(8,17): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(9,21): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(11,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(13,22): error TS2503: Cannot find namespace 'firebase'.


webpack: Failed to compile.
webpack: Compiling...
 90% chunk assets processingERROR in node_modules/@firebase/database/dist/esm/src/api/Database.d.ts(4,33): error TS2307: Cannot find module '@firebase/app-types/private'.
node_modules/@firebase/database/dist/esm/src/core/AuthTokenProvider.d.ts(17,39): error TS2307: Cannot find module '@firebase/app-types/private'.
node_modules/angularfire2/auth/auth.d.ts(10,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/auth/auth.d.ts(11,36): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/database.d.ts(7,15): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/database/interfaces.d.ts(3,50): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(3,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(12,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(42,40): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(43,41): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/interfaces.d.ts(44,37): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/database/list/audit-trail.d.ts(7,133): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/database/list/state-changes.d.ts(6,135): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/database/list/state-changes.d.ts(7,113): error TS2503: Cannot find namespace 'database'.
node_modules/angularfire2/firebase.app.module.d.ts(5,45): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(8,17): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(9,21): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(11,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(13,22): error TS2503: Cannot find namespace 'firebase'.
                                                                                                                                                                                                                                                                                     Date: 2017-12-20T10:00:59.912Z
Hash: e4bd8e4f1e7cf9d121a8
Time: 4196ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry]
chunk {main} main.bundle.js (main) 67 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 546 kB [initial] [rendered]
chunk {scripts} scripts.bundle.js (scripts) 72.7 kB [initial]
chunk {styles} styles.bundle.js (styles) 918 kB [initial]
chunk {vendor} vendor.bundle.js (vendor) 11.3 MB [initial] [rendered]

webpack: Compiled successfully.

Here's what I do to get my project working:

Run ng serve. It fails. Then I open a file. Save small changes. ng serve reattempts compilation. It works. See above.

dunlavy avatar Dec 20 '17 09:12 dunlavy

I have the exact same output as @dunlavy. Im pissed off, and willing to do anything by now... Tried everything in this thread.

EDIT: Apparently it works being pissed off - here's how i managed it (not sure if everything is necessary though):

  1. npm uninstall firebase
  2. npm install firebase
  3. import in main.ts: import * as firebase from 'firebase';
  4. rename imports in the firebase.service.ts to: import * as firebase from 'firebase';

blixenkrone avatar Dec 20 '17 13:12 blixenkrone

Have a look at #https://github.com/firebase/firebase-js-sdk/issues/387 & #https://github.com/firebase/firebase-js-sdk/issues/388.

Now you need to use the new type reference as @myspivey mentioned in the 2nd issue. They had a refactoring on typings in 4.8.1.

But if you are just bothered to change any of your code, fixing your firebase dependency version to 4.8.0 will solve these errors for you.

vzts avatar Dec 20 '17 18:12 vzts

Thank you @paulimfavarato & @vzts that worked, using 4.8.0 works for me, with the above configuration from my last post. 💯 It will save a lot of headaches if you use "firebase": "4.8.0".

ghost avatar Dec 20 '17 20:12 ghost

I also just had this issue.

Upgrading firebase to version 4.8.0 fixed it, but 4.8.1 breaks it again, so if anyone is having problems, make sure you use 4.8.0, not 4.8.1

Metsuryu avatar Dec 21 '17 11:12 Metsuryu

you only need to uninstall firebase and reinstall

npm uninstall firebase

npm install --save [email protected]

delete node modules and reinstall it

rm -rf node_module && npm i

VictorAnquino avatar Dec 21 '17 23:12 VictorAnquino

#https://github.com/firebase/firebase-js-sdk/issues/388

vzts avatar Dec 23 '17 16:12 vzts

Thank you all for your excellent contributions, BTW!

dunlavy avatar Jan 03 '18 03:01 dunlavy

For me forced installing npm install [email protected] helped Which also suggested @VictorAnquino

vladkalyuzhny avatar Jan 07 '18 08:01 vladkalyuzhny

VictorAnquino's solution worked for me. It sucks that we're tied to a specific version of firebase though... We really need a better solution.

MrDrProfX avatar Jan 08 '18 20:01 MrDrProfX

  1. Inside package.json, remove ^ from "firebase": "^4.8.1" 1.1 Downgrade Firebase from 4.8.1 to 4.8.0 by changing 4.8.1 to 4.8.0 1.2 End result should look like this: "firebase": "4.8.0"
  2. Run npm update in the Project Root. NPM will downgrade Firebase for ya
  3. Run ng serve --open to check for compilation errors. There shouldn't be any.

ashrafalngar4 avatar Jan 09 '18 03:01 ashrafalngar4

There's version 4.8.2. I've updated it and it seems to be fixed now.

irman avatar Jan 13 '18 13:01 irman

@irman Confirmed.

dunlavy avatar Jan 26 '18 07:01 dunlavy

@dunlavy @irman Did you do any other fix other than the ones suggested ? this error suddenly started cropping up for me and not able to resolve it.

I tried the following

npm uninstall firebase npm cache clear --force npm install [email protected]

Even tried npm install firebase --latest

Nothing works I tried 4.8.2 , even that does not work.

chezdrz avatar Jan 28 '18 13:01 chezdrz

This worked for me 👍

  "angularfire2": "5.0.0-rc.6",
 "firebase": "4.8.2",

Note: Don't forget to delete node_modules folder and npm i.

Sampath-Lokuge avatar Jan 29 '18 09:01 Sampath-Lokuge

@chezdrz Sorry for the late response. I took a vacation. ;-)

I used the troublesome work-around I posted above. May or may not work for you I suppose, but I was able to develop this way for awhile before I simply updated my project dependencies to 4.8.2. That cleared everything up for me perfectly. Be sure to update AngularFire and perhaps even Angular if you're not using the very latest release (and that doesn't break your project).

dunlavy avatar Feb 08 '18 07:02 dunlavy

import * as firebase from 'firebase ; should fix the problem

JuniaYulia avatar May 05 '18 01:05 JuniaYulia

If anyone is still wondering, just check the new documentation for npm firebase (https://www.npmjs.com/package/firebase), especially the way it is now imported:

import * as firebase from 'firebase';

Many old tutorials have not changed this paticular line and there is not much support available online for it too. Hope this helps a few.

It worked to me.

TheAhmadSharif avatar May 04 '20 08:05 TheAhmadSharif