Firebase-js-sdk: import firebase from 'firebase/app' doesn't compile in angular 6

Created on 20 Aug 2018  路  6Comments  路  Source: firebase/firebase-js-sdk

Hi, when I do these imports in an Angular service, it runs into a compilation error.

[firebase-authentication.service.ts]
... ...
import { Injectable } from '@angular/core';
import firebase from 'firebase/app';
import 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
... ...

ERROR in src/app/service/sdk/authentication/firebase-authentication.service.ts(3,8): error TS1192: Module '"/vagrant/workspace/src/gitlab.com/tamama/ai-google-prive-dialogflow/ai-google-prive-dialogflow/target/angular/tamama/node_modules/firebase/index"' has no default export.

...

However, when I replace one of the line by:
import * as firebase from 'firebase/app';

It compiles. Any best practice?

Kind regards,
Tamama

needs-triage

Most helpful comment

Hi @tamama! For TypeScript you need to use

import * as firebase from 'firebase/app';
// You don't need to import firebase/app either since it's being imported above
import 'firebase/auth';
import 'firebase/firestore';

That should do the trick, and thanks for using the sub packages! 馃檶

All 6 comments

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

Hi @tamama! For TypeScript you need to use

import * as firebase from 'firebase/app';
// You don't need to import firebase/app either since it's being imported above
import 'firebase/auth';
import 'firebase/firestore';

That should do the trick, and thanks for using the sub packages! 馃檶

Hey @davideast, thank you so much!

Kind regards,
Tamama

Hello, I am getting this issue with create-react-app with typescript defaults

error:

import * as firebase from "firebase/app";
/// etc

  componentWillMount() {
    const ref = firebase.database().ref("/projects");
    /// etc
  }

screen shot 2018-10-14 at 1 16 00 pm

For the issue of firesql change the firebase import in firesql.d.ts file to be like this :
From import firebase from 'firebase/app'; To import * as firebase from 'firebase/app';

Was this page helpful?
0 / 5 - 0 ratings