1

When I deploy my firebase function, the deployment fails because of what appear to be syntax issues. See the terminal window in the screenshot. The errors include mostly “Strings must be doublequote” and “Expected indentation of 8 spaces but found 2 tabs”. In the VisualStudio IDE, I don’t see these errors in-line so I’m trying to figure out why these errors appear when I try to deploy this function to Firebase.

I am using Typescript in Visual Studio and deploying to Firebase via the firebase deploy --only functions command in the terminal.

Terminal Output:

(base) samyoon@Sams-MBP FitnessApp % firebase deploy --only functions      

=== Deploying to 'fitnessapp-b3eea'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

lint
eslint --ext .js,.ts .


/Users/samyoon/Documents/FitnessApp/functions/src/index.ts
   1:19  error    Require statement not part of import statement     @typescript-eslint/no-var-requires
   1:27  error    Strings must use doublequote                       quotes
   2:15  error    Require statement not part of import statement     @typescript-eslint/no-var-requires
   2:23  error    Strings must use doublequote                       quotes
   4:16  error    Strings must use doublequote                       quotes
   7:15  error    Strings must use doublequote                       quotes
   8:22  warning  'context' is defined but never used                @typescript-eslint/no-unused-vars
  14:1   error    Unexpected tab character                           no-tabs
  14:1   error    Mixed spaces and tabs                              no-mixed-spaces-and-tabs
  17:1   error    Unexpected tab character                           no-tabs
  17:1   error    Mixed spaces and tabs                              no-mixed-spaces-and-tabs
  18:1   error    Unexpected tab character                           no-tabs
  18:1   error    Expected indentation of 8 spaces but found 2 tabs  indent
  19:1   error    Unexpected tab character                           no-tabs
  19:1   error    Expected indentation of 8 spaces but found 2 tabs  indent
  19:9   error    Strings must use doublequote                       quotes
  20:1   error    Unexpected tab character                           no-tabs
  20:1   error    Expected indentation of 8 spaces but found 2 tabs  indent
  20:9   error    Strings must use doublequote                       quotes
  21:1   error    Unexpected tab character                           no-tabs
  21:1   error    Expected indentation of 6 spaces but found 1 tab   indent
  21:4   error    Missing semicolon                                  semi

✖ 22 problems (21 errors, 1 warning)
  11 errors and 0 warnings potentially fixable with the `--fix` option.


Error: functions predeploy error: Command terminated with non-zero exit code 1

Code:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
import {} from 'firebase-admin';

exports.createUser = functions.firestore

.document('users/{userId}')
.onCreate((snap, context) => {
  // Get an object representing the document
  // e.g. {'name': 'Marie', 'age': 66}
  const userData = snap.data();

  // access a particular field as you would any JS property
  const userUID = userData.uid;

  // perform desired operations ... create new WorkoutCycle document
  admin.collection("WorkoutCycles").doc().set({
    createdTimestamp: Date.now(),
    name: 'FunctionCreatedMe',
    user: 'users/'+userUID,
})
});

Here's a screen recording of the issue: https://www.loom.com/share/881de3fe7e2f45ccb4f99155b69c5bea

Here's a screen shot of the issue: Screenshot of Visual Studio IDE and Terminal

Sam Yoon
  • 53
  • 5
  • You should not post code (or error/exception messages, log files, configuration files, project files, or anything else that is represented in textual form) as an image https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question/285557#285557 – John Hanley Aug 18 '22 at 03:48
  • Thank you-- I've updated the original post with the Terminal Output and Code in code blocks. – Sam Yoon Aug 18 '22 at 04:08
  • Go through the error messages and fix each one. If you do not know what a message means put the string into Google Search. – John Hanley Aug 18 '22 at 04:16

1 Answers1

0

I was able to solve this. I went to my firebase.json file which looked like this:

    {
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  }
}

and deleted this part:

"predeploy": [
  "npm --prefix \"$RESOURCE_DIR\" run lint",
  "npm --prefix \"$RESOURCE_DIR\" run build"
]

Afterwards I deployed my function using this command:

firebase deploy --only functions

And my function successfully deployed to Firebase and I am able to see it in the console.

Although the use cases were different, this github post was helpful in discovering the solution.

Sam Yoon
  • 53
  • 5
  • in other words you deactivated your [linting process](https://stackoverflow.com/questions/8503559/what-is-linting), which may be a bad idea because linting improves code quality. – Renaud Tarnec Aug 18 '22 at 07:46
  • I'd prefer to reactivate it, but it seems to be causing the errors I shared in my post. Any thoughts on why/how the linting process may be causing my code to have these errors? – Sam Yoon Aug 19 '22 at 03:26
  • Because it’s configured to detect those errors. You can adapt the config: https://eslint.org/docs/latest/user-guide/configuring/ – Renaud Tarnec Aug 19 '22 at 04:49