1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Firebase Firestore firestore.Timestamp.now() でエラー v11.5.0

Posted at

Firestoreに現在時刻をfirestore.Timestamp.now() で取得して保存しようとしたのですが、エラーが出てしましました。
Firebaseのバージョンは11.5.0です。

firestore().collection("users").doc(id).set({
  createdAt: firestore.Timestamp.now()
});
error
TypeError: Cannot read properties of undefined (reading 'now') at C:\Users\*ファイル名*

解決策

import { Timestamp } from 'firebase-admin/firestore'を追加して呼び出すと解決しました。
参考に記載したリンクによるとv11の問題と思われます。

import { Timestamp } from 'firebase-admin/firestore'

firestore().collection("users").doc(id).set({
  createdAt: Timestamp.now()
});

参考

[Firestore] admin.firestore.Timestamp.now() fails with firebase-admin 11, works in 10.3 (emulator) #1827

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?