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

This has worked as a simple workaround for me:

In the main app.module.ts for my app (right before I first use the AngualarFireModule), I import the Firebase typings without actually using them (it's enough to cause the firebase namespace to be registered, apparently).

In other words:

import {AngularFireModule} from "angularfire2";
import * as firebase from 'firebase'; // This is just to make the compiler happy

hasMobi avatar Oct 15 '16 20:10 hasMobi

I put ///<reference path="../node_modules/firebase/firebase.d.ts"/> at the top line of main.ts so it loads firebase before Angular.

paulimfavarato avatar Oct 16 '16 10:10 paulimfavarato

I've updated my solution:

angular-cli: 1.0.0-beta.17 node: 6.6.0 os: win32 x64

npm install -g typescript@next
npm install -g typings
npm install -g angular-cli

ng new my_project
cd my_project
npm install angularfire2 firebase --save
//DO NOT INSTALL @types/firebase - it will generate conflicts on new version of typescript
put import 'firebase/firebase'; on polyfills.ts
//do the angularfire configuration in the ngModule.
//do any operation with it.
ng serve //no errors related.

paulimfavarato avatar Oct 18 '16 10:10 paulimfavarato

@paulimfavarato put import on polyfills.ts is not a right semantic solution. I think add a reference on to typings.d.ts will be more semantic correct.

Here is my src/typings.d.ts content of my angular-cli 1.0.0-beta.17 project.

// Typings reference file, see links for more information
// https://github.com/typings/typings
// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html
/// <reference path="../node_modules/firebase/firebase.d.ts" />

declare var System: any;

doggy8088 avatar Oct 21 '16 05:10 doggy8088

Thanks all for help!

I've combined the solutions by @hansanker and @paulimfavarato. And that's works fine for me:

// REMOVE this from tsconfig.json
"typeRoots": [
  "./node_modules/@types"
],
"types": [
  "firebase"
]

// ADD this to tsconfig.json:
"files": [
  "../node_modules/firebase/firebase.d.ts"
]

// then run a command if firebase's types was installed:
npm uninstall @types/firebase

AlexCSR avatar Oct 27 '16 08:10 AlexCSR

I tried everything and it still showing me cannot find namespace 'firebase' for ionic build. however I can run ionic serve. tsconfig file

  "typeRoots": [
    "../node_modules/@types"
  ],
  "types": [
    "firebase",
    "angular"
  ],
  "exclude": [
    "node_modules"
  ],

in the package json I have custom rollup

  "config": {
    "ionic_rollup": "./scripts/rollup.config.js"
  }

rollup.config.js

console.log("Custom rollup fired!!!");
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var globals = require('rollup-plugin-node-globals');
var builtins = require('rollup-plugin-node-builtins');
var json = require('rollup-plugin-json');


// https://github.com/rollup/rollup/wiki/JavaScript-API

var rollupConfig = {
    entry: 'src/app/main.dev.ts',
    sourceMap: true,
    format: 'iife',
    dest: 'main.js',
    useStrict: false,
    plugins: [
        builtins(),
        commonjs({
            include: [
                'node_modules/rxjs/**',
                'node_modules/firebase/**',
                'node_modules/angularfire2/**'
            ],
            namedExports: {
                'node_modules/firebase/firebase.js': ['initializeApp', 'auth', 'database'],
                'node_modules/angularfire2/node_modules/firebase/firebase-browser.js': ['initializeApp', 'auth', 'database']
            }
        }),
        nodeResolve({
            module: true,
            jsnext: true,
            main: true,
            browser: true,
            extensions: ['.js']
        }),
        globals(),
        json()
    ]

};

if (process.env.IONIC_ENV == 'prod') {
    // production mode
    rollupConfig.entry = '{{TMP}}/app/main.prod.ts';
    rollupConfig.sourceMap = false;
}
module.exports = rollupConfig;

alexandrzavalii avatar Oct 28 '16 15:10 alexandrzavalii

There is not a firebase3.d.ts inside of angularfire2 directory.

mpeguero avatar Oct 31 '16 20:10 mpeguero

3 days of search and get nothing

almgwary avatar Nov 21 '16 00:11 almgwary

@almgwary Please try to add a firebase.d.ts reference on to typings.d.ts.

Here is a src/typings.d.ts file in your angular-cli project, just add the following line into that file should works.

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

doggy8088 avatar Nov 21 '16 02:11 doggy8088

Hi anyone knows whats wrong. ERROR in ./~/firebase/app/shared_promise.js Module not found: Error: Can't resolve 'promise-polyfill' in 'C:\Users\IBM_ADMIN\ng2-tuts\king-tutor-app\node_modules\firebase\app' @ ./~/firebase/app/shared_promise.js 22:35-62 @ ./~/firebase/app/firebase_app.js @ ./~/firebase/app.js @ ./~/firebase/firebase-browser.js @ ./~/angularfire2/angularfire2.js @ ./~/angularfire2/index.js @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts webpack: Failed to compile.

vikvincer avatar Apr 18 '17 03:04 vikvincer

@doggy8088 new angularfire have the src\declarations.d.ts, works the same.

crazyhalls avatar Apr 19 '17 21:04 crazyhalls

@vikvincer you need to install the missing promise-polyfill, which is not available by default in the newer releases. https://www.npmjs.com/package/promise-polyfill :)

kehkashanF avatar Jul 03 '17 06:07 kehkashanF

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.

kehkashanF avatar Jul 03 '17 06:07 kehkashanF

Hi everyone, I have the same issu and it's wasting my time. So please, did someone find the solution ? I've tried everything but nothing, need help To be sure you'll understand my problem, please look at the pictures : is

I don't know if I'm right but I think the problem comes from here. issu

PS : I'm working on an Ionic project

david95thinkcode avatar Jul 07 '17 15:07 david95thinkcode

@david95thinkcode Did you try 'firebase' instead of 'firebase/app'?

It seems the documentation was recently changed:

// This import loads the firebase namespace along with all its type information. import * as firebase from 'firebase/app'; // These imports load individual services into the firebase namespace. import 'firebase/auth'; import 'firebase/database';

I manged to solve the problem in my Ionic app using this import.

kehkashanF avatar Jul 07 '17 15:07 kehkashanF

Mine is already working

on app.module.ts

import { AngularFireModule } from 'angularfire2'; import { FirebaseService } from './service/firebase.service' import { AngularFireDatabaseModule } from 'angularfire2/database';

firebase.service.ts

import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';

On Fri, Jul 7, 2017 at 11:40 PM, kehkashanF [email protected] wrote:

@david95thinkcode https://github.com/david95thinkcode Did you try 'firebase' instead of 'firebase/app'?

It seems the documentation was recently changed:

`// This import loads the firebase namespace along with all its type information. import * as firebase from 'firebase/app';

// These imports load individual services into the firebase namespace. import 'firebase/auth'; import 'firebase/database';`

I manged to solve the problem in my Ionic app using this import.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/234#issuecomment-313717364, or mute the thread https://github.com/notifications/unsubscribe-auth/AQ2tqu40NVrIRsYq8AnGXH7KTRmtIQ5lks5sLlF3gaJpZM4I4JbM .

vikvincer avatar Jul 07 '17 15:07 vikvincer

@kehkashanF I've tried that this too but it didn't work. Yeah, I saw the changes in the docs and tried the new specifications but it still not working :(

david95thinkcode avatar Jul 07 '17 15:07 david95thinkcode

Issue fixed. I've reinstall firebase and everything work perfectly 👌

david95thinkcode avatar Jul 09 '17 19:07 david95thinkcode

Just run yarn remove firebase --save then clean cache and run yarn add firebase --save It is losing ref to the namespace of firebase not an angularfire2 issue.

Suka1215 avatar Dec 19 '17 23:12 Suka1215

ERROR in error TS6053: File '/node_modules/angularfire2/firebase3.d.ts' not found.

Ok the above error is a nightmare now.

/myPackageName/package.json

 "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "angularfire2": "^5.0.0-rc.5-next",
    "firebase": "4.8.0", 
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "uuid": "^3.1.0",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.6.1",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

ghost avatar Dec 20 '17 01:12 ghost