Home > Back-end >  Firebase Cloud Function increment counter in Firestore on CreateUser
Firebase Cloud Function increment counter in Firestore on CreateUser

Time:04-06

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?

CodePudding user response:

Try to add this to your config file:

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