Firebase functions cannot deploy : SyntaxError: Unexpected token function
As of September 2019:
- Update firebase-admin :
npm install --save firebase-admin
- Update firebase-functions :
npm install --save firebase-functions
- Add
"engines": { "node": "10" }
to your /functions/package.json
...
"dependencies": {
"firebase-admin": "^8.5.0",
"firebase-functions": "^3.2.0"
},
"devDependencies": {
"tslint": "~5.19.0",
"typescript": "~3.6.2"
},
"engines": {
"node": "10"
}
...
As of August 2018:
Cloud Functions now support Node 8 (8.11.1). Check out this blog post.
Upgrade to Node 8
As suggested in this blog post, follow these steps to upgrade to Node 8:
- Upgrade your firebase-functions version via
npm install --save firebase-functions@latest
- Upgrade firebase-tools via
npm update -g firebase-tools
- Add
"engines": { "node": "8" }
to your/functions/package.json
If you are still having the issue on a recent version (such as node 12), use the ecmaVersion parser option in your .eslintrc.js
file.
Here's a sample:
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
parserOptions: {
ecmaVersion: 8,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
h/t to Dean for the original suggestion.