firebase cloud functions sample code error

Viewed 494

Please help:

I'm new to firebase cloud functions and face the below problem when I follow the startup guide provided by Google.

Below is the startup template index.js file

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
admin.initializeApp();

 // Create and Deploy Your First Cloud Functions
 // https://firebase.google.com/docs/functions/write-firebase-functions

 exports.helloWorld = functions.https.onRequest((request, response) => {
   functions.logger.info("Hello logs!", {structuredData: true});
   response.send("Hello from Firebase!");
 });

When I type firebase deploy in the terminal. It gives me these error codes:

-  1:1   error  This line has a length of 85. Maximum allowed is 80  max-len
-  2:27  error  Strings must use doublequote                         quotes
-  5:23  error  Strings must use doublequote                         quotes
-  8:1   error  Expected indentation of 0 spaces but found 1         indent
-  9:1   error  Expected indentation of 0 spaces but found 1         indent
-  11:1   error  Expected indentation of 0 spaces but found 1         indent
-  12:1   error  Expected indentation of 2 spaces but found 3         indent
-  13:1   error  Expected indentation of 2 spaces but found 3         indent
-  14:1   error  Expected indentation of 0 spaces but found 1         indent

āœ– 9 problems (9 errors, 0 warnings)
  8 errors and 0 warnings potentially fixable with the `--fix` option.

-npm ERR! code ELIFECYCLE
-npm ERR! errno 1
-npm ERR! functions@ lint: `eslint .`
-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!     C:\Users\alant\AppData\Roaming\npm-cache\_logs\2021-06-21T13_22_47_971Z-debug.log
-events.js:292
      throw er; // Unhandled 'error' event
      ^

-Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
    at notFoundError (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.cp.emit (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
  path: 'npm --prefix "%RESOURCE_DIR%" run lint',
  spawnargs: []
}

-Error: functions predeploy error: Command terminated with non-zero exit code1
2 Answers

Run this in the terminal:

eslint --fix

@Hamada After studying the eslint documentation. I finally do this
Add this at start and at the end.

`/* eslint-disable */     

//My code (all rules will be disable)    

/* eslint-enable */`    

Eg.

`// The Cloud Functions for Firebase SDK to  
// create Cloud Functions and setup triggers.  
/* eslint-disable */  
const functions = require('firebase-functions');  

// The Firebase Admin SDK to access Firestore.  
const admin = require('firebase-admin');  
admin.initializeApp();  

 // Create and Deploy Your First Cloud Functions  
 // https://firebase.google.com/docs/functions/write-firebase-functions  

 exports.helloWorld = functions.https.onRequest((request, response) => {    
   functions.logger.info("Hello logs!", {structuredData: true});  
   response.send("Hello from Firebase!");  
   /* eslint-enable */  
});`    
Related