Cloud Functionsdeploy (Unexpected tocken) I'm getting error (30:37 error Parsing error: Unexpected token followedUserRef) when I deploy my code

Cloud Functionsdeploy (Unexpected tocken) I'm getting error (30:37 error Parsing error: Unexpected token followedUserRef) when I deploy my code

我尝试使用 clound 函数 (Nodejs) 获取文档并将其添加到 firestore 数据库。但是我每次部署代码时都会出错。

exports.onCreateFollower = functions.firestore.document("/followers/{userId}/userFollers/{followerId}")
    .onCreate((snapshot, context) => {
        console.log("Follower created", snapshot.data);
        const userId = context.params.userId;
        const followerId = context.params.followerId;

        // get followed users post
        const followedUserPostRef = admin.firestore().collection('posts').doc(userId).collection('userPosts');

        // get following users time line
        const timelinePostRef =  admin
            .firestore()
            .collection('timeline')
            .doc(followerId)
            .collection('timelinePosts');

        // get the followed users posts
        const querysnapshot = await followedUserPostRef.get();

        // add each user posts to users timeline
        querysnapshot.forEach(doc => {
            if (doc.exists) {
                const postId = doc.id;
                const postData = doc.data();
                timelinePostRef.doc(postId).set(postData);
            }
        });
    });

我收到下面给出的错误...

` ** 运行 命令:npm --prefix "$RESOURCE_DIR" 运行 lint

functions@ lint C:\Users\Yousuf Khan\Documents\flutter\instagram_clone\functions eslint .

C:\Users\Yousuf Khan\Documents\flutter\instagram_clone\functions\index.js 30:37 错误解析错误:意外的标记 followedUserRef

✖ 1 个问题(1 个错误,0 个警告)

npm 错误!代码生命周期 错误!错误号 1 错误!函数@ lint:eslint . 错误!退出状态 1 错误! 错误! functions@lint 脚本失败。 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。

npm 错误!此 运行 的完整日志可在以下位置找到: 错误! C:\Users\YousufKhan\AppData\Roaming\npm-cache_logs21-04-04T07_21_32_055Z-debug.log events.js:291 扔呃; // 未处理的 'error' 事件 ** `

//oncreate function should be async
exports.onCreateFollower = functions.firestore.document("/followers/{userId}/userFollers/{followerId}")
    .onCreate(async (snapshot, context) => {
        console.log("Follower created", snapshot.data);
        const userId = context.params.userId;
        const followerId = context.params.followerId;

        // get followed users post
        const followedUserPostRef = admin.firestore().collection('posts').doc(userId).collection('userPosts');

        // get following users time line
        const timelinePostRef =  admin
            .firestore()
            .collection('timeline')
            .doc(followerId)
            .collection('timelinePosts');

        // get the followed users posts
        //I have used await here
        const querysnapshot = await followedUserPostRef.get();

        // add each user posts to users timeline
        querysnapshot.forEach(doc => {
            if (doc.exists) {
                const postId = doc.id;
                const postData = doc.data();
                timelinePostRef.doc(postId).set(postData);
            }
        });
    });

我在 followedUserPostRef.get() 之前使用了等待词​​。所以我必须让这个函数异步。我还没有这样做,这就是为什么会发生错误。