ESlint 解析错误:部署 firebase 函数时出现意外令牌 =>

时间:2021-02-10 10:34:29

标签: firebase parsing google-cloud-firestore eslint

代码:

exports.detectEvilUsers = functions.firestore
    .document('messages/{msgId}')
    .onCreate(async (doc, ctx) => {
// code 
});

当我尝试“firebase deploy --only functions”时,出现消息 ESlint Parsing error: Unexpected token =>

这是我的 package.json:

{
  "name": "firebase project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/eslint-parser": "^7.12.13",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "babel-jest": "^26.6.3",
    "firebase": "^8.2.6",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-firebase-hooks": "^2.2.0",
    "react-scripts": "4.0.2",
    "reactstrap": "^8.9.0",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/preset-env": "^7.12.13",
    "eslint": "^7.19.0",
    "eslint-plugin-react": "^7.22.0"
  }
}

我的 .eslintrc.js:

module.exports = {
    "env": {
        "browser": true,
        "es2021": true
    },
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
};

和我在 /functions 中的 package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "12"
  },
  "main": "index.js",
  "dependencies": {
    "@babel/eslint-parser": "^7.12.13",
    "bad-words": "^3.0.4",
    "firebase-admin": "^9.2.0",
    "firebase-functions": "^3.11.0"
  },
  "devDependencies": {
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

和 /functions 中的 .eslintrc.js:

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

我安装了 babel,尝试了几个配置。到目前为止没有任何效果。我不知道该怎么办。

1 个答案:

答案 0 :(得分:0)

// I think you have forgot to add closing } 
// this is the right way to create a trigger if there is still an error then that error would not be a trigger error
exports.myTrigger = functions.firestore
  .document('collection-name/{id}')
  .onCreate((snap, context) => { 
  
       const id = context.params.id;
       const data = snap.data();
  
  })