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
I tried every solution, nothing worked except this:
First you should know that I have an Angular 2.0 CLI project. - > is the final release, no RC bullshit, - with webpack.
Only 2 files are available for configuration now: tsconfig.json and typings.json - you _don't touch any of them_. In tsconfig.json you shoud have this:
"typeRoots": [
"../node_modules/@types"
]
As you can see, the types are in @types folder form node_modules. What we need to do:
- 👉 Create a
firebasefolder inside the @types folder. - 👉 Inside
firebasefolder create a file called:index.d.ts - 👉 Paste the content from this url inside the index file : https://gist.githubusercontent.com/cdcarson/28399c50b02bf6c507fbf5b7b30daa31/raw/fa089d231ca4253d4715f8161efc6af74c972dfa/firebase-sdk-3-typings.d.ts - many thanks to @joaogarin :) !!
I guess this is the standard way to add typings now.. you can see that it's the same for jasmine - which is added automatically by the CLI.
I can't belive i lost half a day behind this. Works now :)
Thanks Alon-Gbbe. Your solutions worked fine. All other attemps failed.
I personally found adding the following code to src/typings.d.ts fixed everything without having to manually add any files
///<reference path="../node_modules/firebase/firebase.d.ts"/>
import * as firebase from 'firebase'; on top of node_modules\angularfire2\angularfire2.d.ts worked!
I have following setup:
angular-cli: 1.0.0-beta.16 node: 6.6.0 os: win32 x64
[email protected] [email protected]
I created a new project: ng new project-name cd project-name
I changed following @angular-lines to use version 2.0.1 in package.json, because installation of firebase and angularfire2 ended with errors:
"@angular/common": "2.0.1", "@angular/compiler": "2.0.1", "@angular/core": "2.0.1", "@angular/platform-browser": "2.0.1",
npm install -> ok
npm install angularfire2 firebase --save -> ok
I did these changes to the project:
https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md#4-setup-ngmodule
ng serve -> Cannot find namespace 'firebase'.
I did following change:
import * as firebase from 'firebase'; on top of node_modules\angularfire2\angularfire2.d.ts
ng serve -> ok
I just opened the node_modules/angularfire2/angularfire2.d.ts and added the import to firebase import * as firebase from 'firebase';
Last step of installation and setup

:)
@jasugh Thanks. Your last line solved my issue. i'm on RC.5
import * as firebase from 'firebase'; on top of node_modules\angularfire2\angularfire2.d.ts
@jasugh
Your solution worked for me. And I am on Windows 10
I created a new project:
ng new project-name
cd project-name
I changed following @angular-lines to use version 2.0.1 in package.json, because installation
of firebase and angularfire2 ended with errors:
"@angular/common": "2.0.1",
"@angular/compiler": "2.0.1",
"@angular/core": "2.0.1",
"@angular/platform-browser": "2.0.1",
npm install
-> ok
npm install angularfire2 firebase --save
-> ok
ng serve
-> Cannot find namespace 'firebase'.
I did following change:
import * as firebase from 'firebase';
on top of node_modules\angularfire2\angularfire2.d.ts
ng serve
-> ok
Thanks @AIon-Gbbe, your step worked
try adding this line under your import
declare let firebase: any; // <== THERE IS AN ERROR IN THE .d.ts file
ie
import { AngularFireModule } from 'angularfire2';
declare let firebase: any; // <== THERE IS AN ERROR IN THE .d.ts file
you do this when you add vanilla js to typescript, its basically saying to typescript that ' firebase' variable exists even if you dont see it right now and it should hopefully remove the error, if it does let me know.
Instead of declaring stuff or adding things to files not under your control try this:
In tsconfig.json add:
"files": [
"../node_modules/firebase/firebase.d.ts"
]
In typings.d.ts add:
///<reference path="../node_modules/firebase/firebase.d.ts" /
Don't forget to remove the import statement from the fangularfire2.d.ts if you added it before.
Restart ng serve and you're good to go.
i tried every solution but still have not found solution any ideas? EDİT:Solved.Thanks for all help.Adding that line to typings.d.ts ///<reference path="../node_modules/firebase/firebase.d.ts" / is enough for me.
EDİT2:I did not change anything,restart angular-cli and error showed up itself again :( can't find definition file for base.
@sercanyuksel I rushed some little template to github. https://github.com/ArsProgramma/Ng2CliWithFirebase
npm install and typings install
After that it should work for you.
@AIon-Gbbe: thank you. this one solved it for me.
thanks all ! I've solved this by mixing some comments that i've found... adding this int tsconfig.json, (right after "typeRoots" node)
"types": [
"firebase"
]
and adding this line to the typings.d.ts:
declare var require: any;
package.json versions:
"angularfire2": "^2.0.0-beta.5",
"firebase": "^3.4.1",
Solution proposed by @jasugh works for me in Windows7
When I add the types filed angular material will throw this error:
Cannot find name 'HammerInput'.
The only was it worked for me is adding it to angularfire2.d.ts/angularfire2 in the node_module folder with import *as firebase from 'firebase'
this changes helped me
tsconfig.json
+ ,"files":["../node_modules/firebase/firebase.d.ts"]
typings.d.ts
+ ///<reference path="../node_modules/firebase/firebase.d.ts"/>
After compare the working solution from @ArsProgramma with my not working solution I found the trick. only add to tsconfig.json :
"files": [ "../node_modules/firebase/firebase.d.ts" ]
Attention: do not add "types": [ "firebase" ]