3

I'm trying to deploy the very first cloud function. It works perfectly fine, but when I try to deploy it in terminal, it sets out warning saying that "functions is declared but it's value is never read".

Is this some common starting mistake, as I am new to this subject? Thank you.

I tried both imports , deploy erros remains same

 // const functions = require('firebase-functions');
import * as functions from 'firebase-functions' 

Errors message

index.ts file code here

2
  • When posting to Stack Overflow, please don't provide screenshots of error messages and code. Copy the text into the question and format it as code so it's easier to read, copy, and search. Commented Apr 9, 2019 at 12:09
  • this might help stackoverflow.com/a/59941420/4378475 Commented Jan 28, 2020 at 2:35

3 Answers 3

2

Your code doesn't declare any Cloud Functions yet, so eslint warns you that you're importing functions but not using it.

The message will disappear when you declare a Cloud Function in your index.js/index.ts. For example, the documentation on getting started contains this example:

exports.addMessage = functions.https.onRequest((req, res) => {
  const original = req.query.text;
  return admin.database().ref('/messages').push({original: original}).then((snapshot) => {
    return res.redirect(303, snapshot.ref.toString());
  });
});

As you can see, this code uses functions in its first line. So if you add this (or any other Cloud Functions declaration) to your code, you're using functions and eslint will no longer warn you about it not being used.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes he does declare a cloud function (cf screen shot)
And... that's one more reason to not show screenshots of code. :) Thanks for pointing that out @Rsmusic. In that case I have no idea why eslint claims that functions is unused.
0

The error will disappear when you finally use "functions" in a cloud function.

nevermind, you are better off using const functions = require('firebase-functions');

when importing firebase-functions in your index.js

======== EDIT : ======

Make sure that you have correctly installed those dependencies, by running those npm commands in the right folder:

npm install firebase-functions@latest firebase-admin@latest --save
npm install -g firebase-tools

3 Comments

I tried ** const functions = require('firebase-functions');** still not working
Thanks @Rsmusic for given time, still not working, i have installed root project level folder and functions level folder.
You should try to re-deploy your index.js to firebase with command: firebase deploy --only:functions
0

Probably solved, but for me I was expecting ~/functions/index.ts to be the file building but the firebase cli added ~/functions/src/index.ts and THAT was the file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.