Angularfire: Can't use FieldValue.serverTimestamp() from @firebase/firestore-types

Created on 20 Mar 2018  路  8Comments  路  Source: angular/angularfire

Version info

Angular:
5.2.8
Firebase:
4.11.0
AngularFire:
5.0.0-rc.6
Other (e.g. Ionic/Cordova, Node, browser, operating system):
Stackblitz - chrome

How to reproduce these conditions

Open the stackblitz
Failing test unit, Plunkr, or JSFiddle demonstrating the problem
https://stackblitz.com/edit/angular-lrgmmu

Steps to set up and reproduce
Open stackblitz

Sample data and security rules
none and allow all

Debug output

Can't find module:
@firebase/firestore-types/index (@0.2.2)

Check your import statements & ensure you're importing the correct module names.

* Errors in the JavaScript console *
none

* Output from firebase.database().enableLogging(true); *
none

Expected behavior

Is this not how you should use FieldValue.serverTimestamp() from '@firebase/firestore-types' - or maybe I am misunderstood something?


The server datetime being saved

Actual behavior


I get this error:
Can't find module:
@firebase/firestore-types/index (@0.2.2)

Check your import statements & ensure you're importing the correct module names.

Most helpful comment

The -types packages are just types and will not work as runtime values. Use the @firebase/app module instead.

import { firebase } from '@firebase/app';

colRef.doc('testDoc').set({
      name: 'testValue',
      // This line works
      lastEdit: firebase.firestore.FieldValue.serverTimestamp(),
      // Should the following line not work?
      anotherEdit: firebase.firestore.FieldValue.serverTimestamp(),
      }, {merge: true})

All 8 comments

The -types packages are just types and will not work as runtime values. Use the @firebase/app module instead.

import { firebase } from '@firebase/app';

colRef.doc('testDoc').set({
      name: 'testValue',
      // This line works
      lastEdit: firebase.firestore.FieldValue.serverTimestamp(),
      // Should the following line not work?
      anotherEdit: firebase.firestore.FieldValue.serverTimestamp(),
      }, {merge: true})

Thanks for the help - it works.
Is there a resume somewhere about @firebase/app?
Is it correct that you now have to install _both_ firebase and @firebase/app, when using angularfire2?

@firebase/app is automatically installed when you installed firebase

Hi @sarunint thanks for clarifying that, but look at the dependency list:

screen shot 2018-03-28 at 11 10 27

Is it just me or are they not documented at all in angularfire2? When do we need the different dependencies? Do we need both firebase and @firebase/app for example?

@dauledk I'll let the Firebase JS master @jshcrowthe give you the full explanation.

@dauledk You don't need to install the @firebase/* ones since they are declared as dependencies of firebase already.

See https://unpkg.com/[email protected]/package.json

Ok - but why are they not just included in firebase then? Sorry for asking those questions, but it would be awesome with some background info about this, when suddenly the package.json changes shape complete, when just upgrading one package :)

Was this page helpful?
0 / 5 - 0 ratings