Reputation: 13
Code:
exports.detectEvilUsers = functions.firestore
.document('messages/{msgId}')
.onCreate(async (doc, ctx) => {
// code
});
When I try "firebase deploy --only functions", the message ESlint Parsing error: Unexpected token => appears
Here's my 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"
}
}
My .eslintrc.js:
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
}
};
and my package.json inside /functions:
{
"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
}
And the .eslintrc.js inside /functions:
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
I installed babel, tried several configs. Nothing works so far. I do not know what to do.
Upvotes: 0
Views: 806
Reputation: 980
I found this here: https://javascript.tutorialink.com/parsing-error-unexpected-token-when-trying-to-deploy-firebase-cloud-function-i-couldnt-find-any-answers-on-here/
It isn't choking on the arrow function per se, but rather the async arrow function.
For some reason eslint as installed by the firebase cli defaults to es6: true
in firebase/.eslintrc.js
. I'm surprised as async arrow functions are pretty common in 2022. Try changing that to something like:
module.exports = {
root: true,
env: {
es2017: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
"quotes": ["error", "double"],
"max-len": "off",
"semi": ["error", "never"],
},
}
I don't know if es2017 is the best version to use in 2022, so someone please inform me what is currently standard.
Upvotes: 1
Reputation: 23
// 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();
})
Upvotes: 0