简体   繁体   中英

Firebase Cloud Function increment counter in Firestore on CreateUser

I would like to use Firebase Cloud Functions to update a value inside my Cloud Firestore database everytime a new user is created. This is how my index.js looks:

const functions = require('firebase-functions');

export const accountCreate = functions.auth.user().onCreate(user => {
    console.log(user.data);
    
    const FieldValue = require('firebase-admin').firestore.FieldValue;
    var userCounterRef = db.collection('data').doc('userCounter');
    userCounterRef.update({ count: FieldValue.increment(1) });
});

Problem: If I run firebase deploy I get this error:

3:1 error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

✖ 1 problem (1 error, 0 warnings)

Error: functions predeploy error: Command terminated with non-zero

exit code1

This is my eslintrc file:

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  rules: {
    quotes: ["error", "double"],
  },
};

What am I missing here?

Try to add this to your config file:

{
   "parserOptions": {
      "sourceType": "module",
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM