lmcq / firebase-firestorm

Firebase Firestorm is an ORM for Firestore which can be used with Typescript.
MIT License
252 stars 19 forks source link

Using firestorm with angular #10

Open Monstrofil opened 4 years ago

Monstrofil commented 4 years ago

I'm trying to use firestorm in angular project, but have unexpected issue related to di (probably).

The thing is that something imports GeoPoint.js before I actually instantiate firebase library (despite the fact that I do that even BEFORE any imports in main.ts):

core.js:4002 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'GeoPoint' of undefined
TypeError: Cannot read property 'GeoPoint' of undefined
    at new GeoPoint (GeoPoint.js:10)

The following patch solves the issue, and everything works fine.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
- var app_1 = require("firebase/app");
+ var app_1 = require("firebase");
/**
 * Wrapper for firestore geopoint class, mainly used to keep
 * imports clean when using the library.
 */
var GeoPoint = /** @class */ (function () {
    function GeoPoint(latitude, longitude) {
        this._native = new app_1.firestore.GeoPoint(latitude, longitude);

You can try this yourself: https://stackblitz.com/edit/angular-kspirb?file=src%2Fapp%2Fapp.module.ts

Probably anyone knows any workarounds or can approve that changing require() to 'firebase' is ok and I can make pull request with this change?

ight-reco commented 4 years ago

I'm facing this issue too. (It's Timestamp and Vue.js in my case though).

I think it's preferred that we stay hold require('firebase/app') and add require('firebase/firestore'). I guess that require('firebase') might outputs warnings like this: https://stackoverflow.com/questions/50707211/warning-it-looks-like-youre-using-the-development-build-of-the-firebase-js-sdk.

vdiaz1130 commented 4 years ago

Any example of configuring FireStorm with AngularFire? I'm initializing Firebase as follows: @NgModule({ declarations: [AppComponent], imports: [ ... AngularFireModule.initializeApp(environment.firebase), ... ]} );

Have not come across examples on how to go about it with Angular.