Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve new ESLint errors in my Cloud Functions project?

Another day another question regarding Firebase:

I am relatively new to Firebase/node.js/npm ...

I'm currently trying to build a mobile app backend with Firebase for a university project. I use node.js and write, not test my functions locally, then I deploy them using the Firebase CLI and "firebase deploy". Everything worked out fine until I started working like one hour ago. I had a small error in my code which I was easily able to fix. In the same "deploy-cycle", Firebase CLI has shown me an available update for firebase-tools suggesting me to use

npm install -g firebase-tools

This is what I did and where my tragedy began. CLI then recommended to uninstall/reinstall

    npm uninstall -g @google-cloud/functions-emulator
    npm install -g @google-cloud/functions-emulator

So I did. Then I tried to deploy my functions (from local index.js) and received the following waring:

Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function

I used npm install -g firebase-tools in order to update firebase CLI but nothing changed.

I thought it would be a good idea to just backup my old project and initialize a new one in a new folder and to connect it to my existing FB-Project and just copy-paste my the content of my old index.js to the one in the new project folder. Trying to deploy this new project, I received a ton of errors and warning concerning my code, like:

18:4   error    Expected catch() or return                  promise/catch-or-return

and many more, even though my coded functions worked fine before.

So I decided that it would probably be the best to try and fix the error with the old project.

Does anyone have a recommendation what to do in this case or where to find these mysterious firebase config variables? I wasn't able to find any solution to my problem online. I'd really appreciate any kind of helping support, since I have no idea what to do and I have no support from my university doing this...

like image 252
nnige Avatar asked Jan 23 '18 18:01

nnige


People also ask

How to disable ESLint for firebase Functions?

If you simply cannot use ESLint right now, you can re-create your project, but choose not to use ESLint when it prompts you. Or you can disable it in your current project by editing your firebase. json file and removing the predeploy script that runs the lint command.

How do you skip ESLint?

To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you're interested in: /* eslint-disable */ console.

How do I use ESLint to fix errors?

There are three ways that ESLint fix can be run: eslint --fix will fix every rule violation it is capable of fixing, actually overwrite the code, and print out any warnings or errors it was incapable of fixing. Most errors are not actually automatically fixable. Take a look at this documentation, the items with the ‘wrench’ image can be auto-fixed.

Should I use ESLint if my Firebase project fails?

The Firebase team strongly recommends you take the advice of those warnings and errors and resolve them, so that your code has fewer problems. If you simply cannot use ESLint right now, you can re-create your project, but choose not to use ESLint when it prompts you.

What are the exit codes for ESLint’s Fix command?

ESLint’s fix command has three possible exit codes: 1 success and no lint errors, less warnings than max warnings 2 linting was successful, at least one lint error or more warnings than max-warnings 3 linting unsuccessful due to config error or internal error

Do warnings result in problems at runtime in ESLint?

Generally, warnings don’t directly result in problems at runtime. However, many rules can be configured to show errors instead of warnings (or vice versa). For example, both of the issues listed above are included as warnings when extending @typescript-eslint/recommended like below in .eslintrc.json:


1 Answers

The error message about config variables asked you to update your Firebase CLI, which you did. And that's fine. (You could have ignored the warning about @google-cloud/functions-emulator.)

When you created a new project, you probably chose to use ESLint during the project creation process. The prompt would have said:

Do you want to use ESLint to catch probable bugs and enforce style?

This is a very new feature in the Firebase CLI since version 3.17.0, and you probably weren't using ESLint previously.

Those new errors you're seeing are ESLint telling you there are potential problems with your code. The Firebase team strongly recommends you take the advice of those warnings and errors and resolve them, so that your code has fewer problems.

If you simply cannot use ESLint right now, you can re-create your project, but choose not to use ESLint when it prompts you. Or you can disable it in your current project by editing your firebase.json file and removing the predeploy script that runs the lint command.

like image 81
Doug Stevenson Avatar answered Oct 14 '22 15:10

Doug Stevenson