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

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:

  1. 👉 Create a firebase folder inside the @types folder.
  2. 👉 Inside firebase folder create a file called: index.d.ts
  3. 👉 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 :)

AionDev avatar Sep 28 '16 09:09 AionDev

Thanks Alon-Gbbe. Your solutions worked fine. All other attemps failed.

ghost avatar Sep 28 '16 15:09 ghost

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"/>

dannymarsland avatar Sep 28 '16 21:09 dannymarsland

import * as firebase from 'firebase'; on top of node_modules\angularfire2\angularfire2.d.ts worked!

hiepxanh avatar Sep 29 '16 02:09 hiepxanh

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

ghost avatar Sep 29 '16 17:09 ghost

I just opened the node_modules/angularfire2/angularfire2.d.ts and added the import to firebase import * as firebase from 'firebase';

andrebaltieri avatar Sep 29 '16 22:09 andrebaltieri

Last step of installation and setup

2016-09-29

:)

l3abyl3oy avatar Sep 30 '16 00:09 l3abyl3oy

@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

candidature avatar Oct 01 '16 17:10 candidature

@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

cryptalith avatar Oct 04 '16 03:10 cryptalith

Thanks @AIon-Gbbe, your step worked

mohanmca avatar Oct 04 '16 23:10 mohanmca

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.

garrettmac avatar Oct 06 '16 16:10 garrettmac

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.

ArsProgramma-private avatar Oct 06 '16 20:10 ArsProgramma-private

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 avatar Oct 07 '16 17:10 sercanyuksel

@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.

ArsProgramma-private avatar Oct 07 '16 18:10 ArsProgramma-private

@AIon-Gbbe: thank you. this one solved it for me.

vargalas avatar Oct 08 '16 14:10 vargalas

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",

mhhansen avatar Oct 11 '16 00:10 mhhansen

Solution proposed by @jasugh works for me in Windows7

07Gond avatar Oct 11 '16 19:10 07Gond

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'

cre8 avatar Oct 12 '16 07:10 cre8

this changes helped me

tsconfig.json

+  ,"files":["../node_modules/firebase/firebase.d.ts"]

typings.d.ts

+  ///<reference path="../node_modules/firebase/firebase.d.ts"/>

panser avatar Oct 12 '16 14:10 panser

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" ]

hansanker avatar Oct 15 '16 16:10 hansanker