node.js - 通过flutter中的节点js文件将firebase与我的项目链接时出现错误
问题描述
我的“日志”部分中的一个匿名错误出现在 firebase 项目上,而 Android Studio 中的“运行”中没有显示任何错误。我对node js一无所知,我只是想通过它链接我的应用程序,这就是我被迫使用它的原因,有人可以帮助我吗?这是firebase项目的完整错误->函数->日志
srv/node_modules/@google-cloud/firestore/build/src/collection-group.js:54
async *getPartitions(desiredPartitionCount) {
^
SyntaxError: Unexpected token *
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/node_modules/@google-cloud/firestore/build/src/index.js:39:28)
这是firebase项目->函数->日志的第二个错误。:
Error detected in onCreateFollower {"errorEvent":{"eventTime":"2020-10-31T06:41:42.682Z","message":"/srv/node_modules/@google-cloud/firestore/build/src/collection-group.js:54\n async *getPartitions(desiredPartitionCount) {\n ^\n\nSyntaxError: Unexpected token *\n at createScript (vm.js:80:10)\n at Object.runInThisContext (vm.js:139:10)\n at Module._compile (module.js:617:28)\n at Object.Module._extensions..js (module.js:664:10)\n at Module.load (module.js:566:32)\n at tryModuleLoad (module.js:506:12)\n at Function.Module._load (module.js:498:3)\n at Module.require (module.js:597:17)\n at require (internal/module.js:11:18)\n at Object.<anonymous> (/srv/node_modules/@google-cloud/firestore/build/src/index.js:39:28)","serviceContext":{"service":"onCreateFollower","resourceType":"cloud_function"}},"@type":"type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.Insight","errorGroup":"COvaxM_ErLfhbg"
这是 Android Studio 中 index.js 文件中的代码 -
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// functions.logger.info("Hello logs!", {structuredData: true});
// response.send("Hello from Firebase!");
// });
exports.onCreateFollower = functions.firestore.document("/followers/{userId}/userFollowers/{followerId}").onCreate(async (snapshot, context) => {
console.log('Follower Created', snapshot.id);
const userId = context.params.userId;
const followerId = context.params.followerId;
const followedUserPostsRef = admin.firestore().collection('posts').doc(userId).collection('userPosts');
const timelinePostsRef = admin.firestore().collection('timeline').doc(followerId).collection('timelinePosts');
const querySnapshot = await followedUserPostsRef.get();
querySnapshot.forEach(doc => {
if(doc.exists) {
const postId = doc.id;
const postData = doc.data();
timelinePostsRef.doc(postId).set(postData);
}
})
});
解决方案
将 firebase-admin 的版本更改为“firebase-admin”:“^ 8.10.0”,将 firebase-functions 更改为“firebase-functions”:“^ 3.6.1”。我也遇到了这个问题并解决了。
推荐阅读
- r - rvest:处理不同数量的嵌套类
- django - ManyToManyField 未保存在数据库中
- r - 为什么列上的 stringr::str_match 返回一个矩阵?
- php - 自定义分类的 Woocommerce 产品存档页面
- c# - C#如何在将用户输入放入我的数组之前验证用户输入?
- sql - postgresql - datetime:postgresql 是否有 mysql 中的 datetime 类型?
- android - 如何在kotlin中将按钮的背景资源从一个自定义drawable设置为另一个自定义drawable?
- java - 如何使用 AndroidStudio 中的 Java 方法从 Firebase 实时数据库中读取值?
- javascript - article.createdAt.toLocalDateString 不是函数
- python-3.x - __init__.py 中的 google.cloud 命名空间导入错误