You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot read property 'Timestamp' of undefined. #2124
// noinspection ES6UnusedImports
import * as firebase from 'firebase/app';
import Timestamp = firebase.firestore.Timestamp; // <== Transaction.ts : 9 in the error log.
export class Transaction {
public date: Date;
....
public greatThingsHere() {
return Timestamp.fromDate(this.date); // Something like that.
}
}
If I disable aot and buildoptimizer in angular.json it works again.
Debug output
Uncaught TypeError: Cannot read property 'Timestamp' of undefined
at Object.1QCC (Transaction.ts:9)
at i (bootstrap:83)
at Object.ZJFI (database.service.ts:3)
at i (bootstrap:83)
at Object.yxOE (index.ngfactory.js.pre-build-optimizer.js:81)
at i (bootstrap:83)
at Module.zUnb (app.component.ts:6)
at i (bootstrap:83)
at Object.0 (user-view-routing.module.ts:34)
at i (bootstrap:83)
@grahamtwine
If done, firebase will complain you are importing everything, and that you should only do that in development. But yeah, maybe for now that's the best workaround we have.
import * as firebase from 'firebase/app';
export class Transaction {
public date: Date;
....
public greatThingsHere() {
return firestore.Timestamp.fromDate(this.date);
}
}
But I don't why it works. Also I have like the original implementation in an interface and It works there.
import * as firebase from 'firebase/app';
import Timestamp = firebase.firestore.Timestamp;
export interface TransactionModel {
date: Timestamp;
...
}
Well I guess It works there cause its just a symbol for TS compiler.
On Thu, 1 Aug 2019 at 18:10, Nikolas Andronopoulos ***@***.***> wrote:
Well I solved it with:
import * as firebase from 'firebase/app';
export class Transaction {
public date: Date;
....
public greatThingsHere() {
return firestore.Timestamp.fromDate(this.date);
}
}
But I don't why it works. Also I have like the original implementation in
an interface and It works there.
import * as firebase from 'firebase/app';
import Timestamp = firebase.firestore.Timestamp;
export interface TransactionModel {
date: Timestamp;
...
}
Well I guess It works there cause its just a symbol for TS compiler.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2124>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGLGSTELC3D7DE2MBV3XCTQCMDJBANCNFSM4H34DBIA>
.
import { Timestamp } from '@firebase/firestore-types';
I think this will be correct, can we close this case? @N-Andronopoulos
It seems like you are actually unable to use that export at run time.
Use the export at runtime? Its a type... I think its supposed to be only compile time. I think you must use other modules when using Timestamp for functionality. But I may be wrong.
// Won't workimportfirebasefrom'firebase/app'console.log(firebase.firestore.Timestamp.now())// Will workimportfirebasefrom'firebase/app'import'firebase/firestore'console.log(firebase.firestore.Timestamp.now())
Reacted by Saul, Shlomo Morosow, NashIlli and Geison Biazus
I have created a file where I have all the imports to make it work, also, I have exported the Timestamp class to make use of it across the application and avoid repeating all the imports again.
// A custom firestore-types.ts/** * To make the Timestamp class to work in a production build, * we need to do all these imports. * * We exported the import to make use of it across the application and avoid * repeating all these imports again. */import*asfirebasefrom'firebase/app';import'firebase/firestore';exportimportTimestamp=firebase.firestore.Timestamp;
Activity
grahamtwine commentedon Aug 1, 2019
try
import * as firebase from 'firebase';LanderBeeuwsaert commentedon Aug 1, 2019
@grahamtwine
If done, firebase will complain you are importing everything, and that you should only do that in development. But yeah, maybe for now that's the best workaround we have.
N-Andronopoulos commentedon Aug 1, 2019
Well I solved it with:
But I don't why it works. Also I have like the original implementation in an interface and It works there.
Well I guess It works there cause its just a symbol for TS compiler.
grahamtwine commentedon Aug 1, 2019
hiepxanh commentedon Feb 7, 2020
import { Timestamp } from '@firebase/firestore-types';I think this will be correct, can we close this case? @N-Andronopoulos
beardo01 commentedon Jun 9, 2020
It seems like you are actually unable to use that export at run time.
N-Andronopoulos commentedon Jun 11, 2020
Use the export at runtime? Its a type... I think its supposed to be only compile time. I think you must use other modules when using Timestamp for functionality. But I may be wrong.
alexandermckay commentedon Sep 9, 2020
In my case I had not imported
firebase/firestoreRRGT19 commentedon Nov 24, 2020
I have created a file where I have all the imports to make it work, also, I have exported the Timestamp class to make use of it across the application and avoid repeating all the imports again.
Example of use:
This is working good for me in production builds.