I'm trying to build a ng2 app with angularfire. Following the quickstart, I receive the following error:
cannot find namespace 'firebase'
Seems to be something with the typings, installed all of them though. Any ideas on this issue?
If you have a fresh angular 2.0 CLI project - this will work - i don't know your particular setup:
tsconfig.json looks like this: "compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types" /// - here - types are pointing to this @types folder inside node_modules.
]
}
@types called firebase.firebase, name it index.d.tsindex.d.tsIt looks like the recommended way to add typing's to an Angular 2.0 CLI project - is to add them inside node_modules/@types folder.. As you can see the jasmine typing's folder looks similar - and was automatically added there by the CLI scaffolding.
It works as described in the issue.
tsconfig.json:
"types": [
"jasmine",
"firebase"
]
Can't believe it's so easy to fix.
tsc -v what version does that report?Version 1.0.3.0 ?npm install -g typescript@next npm install typescript@next --save-devIt seems that bug has already been reported and (hopefully) being worked on. Check it out here:
https://github.com/angular/angularfire2/issues/461
Some people had success modifying typings.json (removing dependcy to firebase) or installing the @next version of typescript. Personally i'm stuck with the same error currently.
I hope the bug gets fixed eventually (soon ;))
EDIT: Seems like the 'bug' was a combination of several dependencies that had to be just right. In the end I had a PATH variable set to point to an old tsc installation under Program Files. For some reason, that was used instead of the (preferred one) from the node package typescript.
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.
Solution:
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.
Reason:
Firebase had introduced some breaking changes that AngularFire2 had not coped up with yet. Until the AngularFire2 team work it out, this will be the solution.
Add a thumbs up emoji and direct anyone having the same trouble here! Would save a lot of their time!