Firebase Deploy Unexpected token

Viewed 62

I am getting the error Parsing error: Unexpected token => when I try to deploy my Vue JS application to firebase. The application runs fine on my local machine but I am not able to deploy to firebase.

Here is the full error

=== Deploying to 'mmmmnl-d5ddc'...

i  deploying storage, firestore, functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint

> lint
> eslint .


/Users/KingdomMac/Downloads/ermnl_delivery/ermnl-dashboard/functions/index.js
  22:71  error  Parsing error: Unexpected token =>

āœ– 1 problem (1 error, 0 warnings)


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

I have added ecmaVersion: 8 to parserOptions. I have changed it to 6, I have also changed it to 2017 as suggested by some other answers.

Here is my .eslintrc.js file

module.exports = {
  root: true,

  env: {
    node: true
  },

  extends: ["plugin:vue/essential", "@vue/prettier"],

  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
  },

  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: 2017
  },

  'extends': [
    'plugin:vue/essential',
    '@vue/prettier',
    '@vue/standard'
  ]
};

Here is my package.json file

{
  "name": "vue-white-dashboard",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.35",
    "@fortawesome/free-brands-svg-icons": "^5.15.3",
    "@fortawesome/free-regular-svg-icons": "^5.15.3",
    "@fortawesome/free-solid-svg-icons": "^5.15.3",
    "@fortawesome/vue-fontawesome": "^2.0.2",
    "axios": "^0.21.1",
    "chart.js": "^2.8.0",
    "core-js": "^2.6.5",
    "firebase": "^8.6.8",
    "node-sass": "^6.0.1",
    "vue": "^2.6.10",
    "vue-chartjs": "^3.4.2",
    "vue-click-outside": "^1.0.7",
    "vue-clickaway": "^2.2.2",
    "vue-github-buttons": "^3.1.0",
    "vue-i18n": "^8.14.1",
    "vue-router": "^3.0.3",
    "vue-social-sharing": "^2.4.6",
    "vue2-transitions": "^0.3.0",
    "vuetify": "^2.4.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.3.0",
    "@vue/cli-plugin-eslint": "^3.1.1",
    "@vue/cli-service": "^4.5.15",
    "@vue/eslint-config-prettier": "^5.0.0",
    "@vue/eslint-config-standard": "^5.1.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^8.2.0",
    "eslint-config-eslint": "^7.0.0",
    "eslint-config-google": "^0.14.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^3.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^7.14.0",
    "prettier": "^1.18.2",
    "sass": "~1.32",
    "sass-loader": "^10.0.0",
    "vue-cli-plugin-vuetify": "~2.4.1",
    "vue-template-compiler": "^2.6.10",
    "vuetify-loader": "^1.7.0"
  }
}

None of the the other resources I have read points out the problem to be from their code. But I am just adding functions/index.js here incase the problem is from the that file.

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();


exports.addUserRole = functions.auth.user().onCreate(async (authUser) => {
  if (authUser.email) {
    const customClaims = {
      admin: true,
    };
    try {
      let _ = await admin.auth().setCustomUserClaims(authUser.uid, customClaims);
      return db.collection("roles").doc(authUser.uid).set({
        email: authUser.email,
        role: customClaims,
      });
    } catch (error) {
      console.log(error);
    }
  }
});

exports.setUserRole = functions.https.onCall(async (data, context) => {
  if (!context.auth.token.admin) return
  try {
    let _ = await admin.auth().setCustomUserClaims(data.uid, data.role)
    return db.collection("roles").doc(data.uid).update({
      role: data.role
    })
  } catch (error) {
    console.log(error)
  }
});

As requested in the comments, I have added my firebase.json

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  },
  "storage": {
    "rules": "storage.rules"
  },
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
0 Answers
Related