admin管理员组

文章数量:1201373

I'm try to deploy fireabase example , but when I try to deploy it , CLI launches an error:

[CODE]

const functions = require('firebase-functions'); //to activate firebase functions

const admin = require('firebase-admin'); //to active firebase database permissions

admin.initializeApp(functions.config().firebase);

exports.addMessage = functions.https.onRequest((req, res) => {
// [END addMessageTrigger]
  // Grab the text parameter.
  const original = req.query.text;
  // [START adminSdkPush]
  // Push the new message into the Realtime Database using the Firebase Admin SDK.
  admin.database().ref('/messages').push({original: original}).then(snapshot => {
    // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
    res.redirect(303, snapshot.ref);
  });
  // [END adminSdkPush]
});

[ERROR]

  15:3   error  Expected catch() or return                  promise/catch-or-return
  15:69  error  Each then() should return a value or throw  promise/always-return

✖ 2 problems (2 errors, 0 warnings)


npm ERR! Darwin 17.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "--prefix" "/Users/user/test/functions" "run" "lint"
npm ERR! node v6.10.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the functions@ lint script 'eslint .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the functions package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     eslint .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs functions
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls functions
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/eliassebastian/Developer/npm-debug.log

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

I take a look to original final provided by firebase here

I'm to new in Javascript and all this world, so I'm really lost with this type of messages.

How can I solve this?

I'm try to deploy fireabase example , but when I try to deploy it , CLI launches an error:

[CODE]

const functions = require('firebase-functions'); //to activate firebase functions

const admin = require('firebase-admin'); //to active firebase database permissions

admin.initializeApp(functions.config().firebase);

exports.addMessage = functions.https.onRequest((req, res) => {
// [END addMessageTrigger]
  // Grab the text parameter.
  const original = req.query.text;
  // [START adminSdkPush]
  // Push the new message into the Realtime Database using the Firebase Admin SDK.
  admin.database().ref('/messages').push({original: original}).then(snapshot => {
    // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
    res.redirect(303, snapshot.ref);
  });
  // [END adminSdkPush]
});

[ERROR]

  15:3   error  Expected catch() or return                  promise/catch-or-return
  15:69  error  Each then() should return a value or throw  promise/always-return

✖ 2 problems (2 errors, 0 warnings)


npm ERR! Darwin 17.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "--prefix" "/Users/user/test/functions" "run" "lint"
npm ERR! node v6.10.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the functions@ lint script 'eslint .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the functions package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     eslint .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs functions
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls functions
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/eliassebastian/Developer/npm-debug.log

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

I take a look to original final provided by firebase here

I'm to new in Javascript and all this world, so I'm really lost with this type of messages.

How can I solve this?

Share Improve this question edited Feb 2, 2018 at 16:41 Doug Stevenson 317k36 gold badges454 silver badges472 bronze badges asked Feb 2, 2018 at 12:02 ShudyShudy 7,93620 gold badges66 silver badges100 bronze badges 4
  • There are many messages here for different concerns. "Make sure you have the latest version of node.js and npm installed." seems clear enough. – Denys Séguret Commented Feb 2, 2018 at 12:04
  • d'ouh totally my fault. Can we close it. Thanks @DenysSéguret – Shudy Commented Feb 2, 2018 at 12:12
  • Even if npm errors are resolved, the eslint warnings are legit and will continue to prevent the code from being deployed. Definitely need to resolve those. – Doug Stevenson Commented Feb 2, 2018 at 16:38
  • I got these error while deploying on firebase 57:14 warning Unexpected function expression prefer-arrow-callback 61:12 error 'ref' is already defined no-redeclare – Prashant Gosai Commented Apr 18, 2019 at 15:59
Add a comment  | 

2 Answers 2

Reset to default 23

The ESLint warnings are legitimate. To get more detail on each one, you can search them using their unique id. For example:

15:3   error  Expected catch() or return                  promise/catch-or-return

The id of the warning here is promise/catch-or-return. Googling for "eslint promise/catch-or-return" finds a plugin for ESLint that describes the warning as:

Enforces the use of catch() on un-returned promises

You're getting this because you have a promise being returned from then, but you never return or catch for possible errors.

The second warning:

15:69  error  Each then() should return a value or throw  promise/always-return

comes from the same ESLint plugin, and is described like this:

Return inside each then() to create readable and reusable Promise chains.

It's requiring you to return a value inside each function called by then, even if you don't have anything special to sent to the next promise chain.

You can resolve both of these problems like this:

admin.database().ref('/messages').push({original: original}).then(snapshot => {
    res.redirect(303, snapshot.ref);
    return null;
}).catch(error => {
    console.error(error);
    res.error(500);
});

Notice that the then block returns null now, and catch is used on the promise returned from then to capture errors and send an error response to the client.

Doug Stevenson answer is partially right as there is one flaw in it.

It should be :

admin.database().ref('/messages').push({original: original}).then(snapshot => {
    res.redirect(303, snapshot.ref);
    return 1; // IT SHOULD RETURN NON-NULL VALUE
}).catch(error => {
    console.error(error);
    res.error(500);
});

The cloud function went into infinite loop when it returned null. And as a result, we can see function timed out after 60,000 ms in the above image.

After such multiple timed out functions, you will get the error functions can be executed (shown in above pic). This is because in Spark Plan (free tier plan), there is limit on CPUMilliSecondsDailyNonbillable .

If you click on Stackdriver's Quota Policy in cloud functions section, you can see the limit in GCD( Google Cloud Platform)

本文标签: javascriptESLint error trying to deploy functions FirebaseStack Overflow