昨天,我重新部署了Google应用程序引擎cron作业cron.yaml和app.yaml,以使它每分钟运行一次。现在,我收到了错误消息
Cannot read property 'seconds' of null
at Function.fromProto (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/timestamp.js:91:46)
at _firestore.request.then.resp (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/write-batch.js:472:42)
我认为这不是函数代码中的错误,因为我已经重新部署了该函数。此外,我尝试访问上述文件,但找不到任何问题的痕迹。部署有问题吗?我该如何解决这个问题?
编辑:
我也开始收到
The behavior for Date objects stored in Firestore is going to change
AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the
following code to your app before calling any other Cloud Firestore methods:
const firestore = new Firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
With this change, timestamps stored in Cloud Firestore will be read back as
Firebase Timestamp objects instead of as system Date objects. So you will also
need to update code expecting a Date to instead expect a Timestamp. For example:
// Old:
const date = snapshot.get('created_at');
// New:
const timestamp = snapshot.get('created_at');
const date = timestamp.toDate();
Please audit all existing usages of Date when you enable the new behavior. In a
future release, the behavior will change to the new behavior, so if you do not
follow these steps, YOUR APP MAY BREAK.
因此,我添加了
const firestore = new Firestore();
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
但是我在部署时收到此错误:
Firestore is not defined
at Object.<anonymous>
答案 0 :(得分:2)
上周,我也开始出现“无法读取属性'seconds'of null”错误。对我来说,它似乎仅在尝试提交没有设置/更新/删除的批处理时出现。您正在使用批处理吗?
关于timestampsInSeconds
错误,请尝试使用admin.firestore()
代替Firestore()
(但仍要配置设置)。
很高兴能从Firebase团队那里获得一些指导,因为他们并没有真正解决功能的timetamsInSeconds。
编辑:
今天,我添加了代码,仅在batch._writes.length> 0时才调用batch.commit(),这似乎可以防止出现“'seconds'of null”错误。有点草率,但是直到Firebase修复其代码后,它才能起作用。