Cannot find namespace 'firebase'.
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
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;
back to version "firebase": "4.8.0". remember to clear your cache. to check the version use npm list firebase
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.
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):
npm uninstall firebasenpm install firebase- import in main.ts:
import * as firebase from 'firebase'; - rename imports in the firebase.service.ts to:
import * as firebase from 'firebase';
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.
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".
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
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
#https://github.com/firebase/firebase-js-sdk/issues/388
Thank you all for your excellent contributions, BTW!
For me forced installing npm install [email protected] helped
Which also suggested @VictorAnquino
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.
- 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"
- Run npm update in the Project Root. NPM will downgrade Firebase for ya
- Run ng serve --open to check for compilation errors. There shouldn't be any.
There's version 4.8.2. I've updated it and it seems to be fixed now.
@irman Confirmed.
@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.
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.
@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).
import * as firebase from 'firebase ; should fix the problem
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.