Just recently started exploring Firebase functions. Managed to install it on my computer, but running into an error when trying to execute:
=== Deploying to 'app'...
i deploying firestore, functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/username/Documents/appdevelopment/app/functions
> eslint --ext .js,.ts .
/Users/username/Documents/appdevelopment/app/functions/index.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-
eslint/parser.
The file does not match your project config: index.js.
The file must be included in at least one of the projects provided
/Users/username/Documents/appdevelopment/app/functions/src/index.ts
1:13 warning 'functions' is defined but never used @typescript-eslint/no-unused-
vars
✖ 2 problems (1 error, 1 warning)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint --ext .js,.ts .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging
output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2021-08-15T21_08_19_284Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
The issue seems to indicate that a required file is missing and mentions a function being defined but unused. Did I overlook something during the installation process?
Here are the commands I used for installing Firebase functions:
- npm install
- npm install -g firebase-tools
- firebase login
- firebase init firestore
- firebase init functions I performed all these within the folder structure: Documents/appdevelopment/app/
This snippet shows my test function setup:
const functions = require("firebase-functions");
const admin = require('firebase-admin');
const db = admin.firestore();
admin.initializeApp();
exports.vote = functions.firestore
.document('Votes/{vote}')
.onCreate((document, context) => {
const row = document.data()['id'];
const vote = document.data()['vote'];
if (vote == 1) {
const field = '1star';
} else if (vote == 2) {
const field = '2star';
} else if (vote == 3) {
const field = '3star';
} else if (vote == 4) {
const field = '4star';
} else {
const field = '5star';
}
const incremento = firebase.firestore.FieldValue.increment(1);
const incrementv = firebase.firestore.FieldValue.increment(1);
db.doc('message/'+row).set({field: incremento, 'votes': incrementv})
});
Upon running firebase deploy, the aforementioned error occurs.
----- edit----
After adding an index.js and an index.ts file (not sure which language defaulted) under functions/src/, the error message changed to:
deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint
/Users/username/Documents/appdevelopment/app/functions
> eslint --ext .js,.ts .
/Users/username/Documents/appdevelopment/
app/functions/src/index.js
0:0 error Parsing error: "parserOptions.project" has been set
for @typescript-eslint/parser.
The file does not match your project config: src/index.js.
The file must be included in at least one of the projects provided
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint --ext .js,.ts .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely
logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2021-08-
16T08_27_58_329Z-debug.log
Error: functions predeploy error: Command terminated with non-
zero exit code1