首页 文章

eslint抛出错误

提问于
浏览
0

我是新的android初学者,并尝试部署firebase功能,但显示一些错误如何解决这个问题PLZ帮助我 .

Firebase database structure

User Table

  • 用户

  • user_id

  • device_token:user_device_token

  • 名称:user_name

Notification Table

  • 通知

  • to_user_id

  • notification_id

  • 来自:from_user_id

Error

Index.js

'use strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


/*
 * 'OnWrite' works as 'addValueEventListener' for android. It will fire the function
 * everytime there is some item added, removed or changed from the provided 'database.ref'
 * 'sendNotification' is the name of the function, which can be changed according to
 * your requirement
 */

exports.sendNotification = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite(event => {


	  /*
	   * You can store values as variables from the 'database.ref'
	   * Just like here, I've done for 'user_id' and 'notification'
	   */

	  const user_id = event.params.user_id;
	  const notification_id = event.params.notification_id;

	  console.log('We have a notification from : ', user_id);

	  /*
	   * Stops proceeding to the rest of the function if the entry is deleted from database.
	   * If you want to work with what should happen when an entry is deleted, you can replace the
	   * line from "return console.log.... "
	   */

	  if(!event.data.val()){

			return console.log('A Notification has been deleted from the database : ', notification_id);

		}

	  /*
	   * 'fromUser' query retreives the ID of the user who sent the notification
	   */

	  const fromUser = admin.database().ref(`/notifications/${user_id}/${notification_id}`).once('value');

	  return fromUser.then(fromUserResult => {

			const from_user_id = fromUserResult.val().from;

			console.log('You have new notification from  : ', from_user_id);

			/*
			 * The we run two queries at a time using Firebase 'Promise'.
			 * One to get the name of the user who sent the notification
			 * another one to get the devicetoken to the device we want to send notification to
			 */

			const userQuery = admin.database().ref(`/Users/${from_user_id}/Name`).once('value');
			const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');

			return Promise.all([userQuery, deviceToken]).then(result => {

			  const userName = result[0].val();
			  const token_id = result[1].val();

			  /*
			   * We are creating a 'payload' to create a notification to be sent.
			   */

			  const payload = {
					notification: {
					  title : "New Friend Request",
					  body: `${userName} has sent you request`,
					  icon: "default",
					
					}
				};

			  /*
			   * Then using admin.messaging() we are sending the payload notification to the token_id of
			   * the device we retreived.
			   */

				  return admin.messaging().sendToDevice(token_id, payload).then(response => {

						console.log('This was the notification Feature');

					});

			});

		});

	});

** cmd显示错误**

C:\ Users \ TahirAliAwan \ Desktop \ Function> firebase deploy ===部署到'videochat-96f75'...我正在部署函数运行命令:npm --prefix%RESOURCE_DIR%run lint functions @ lint C:\ Users \ TahirAliAwan \ Desktop \ Function \ functions eslint . C:\ Users \ TahirAliAwan \ Desktop \ Function \ functions \ index.js 61:11警告避免嵌套承诺promise / no-nesting 84:14警告避免嵌套promises promise / no-nesting 84:69错误每次then()都应该返回一个值或抛出承诺/总是返回problems3个问题(1个错误,2个警告)npm ERR! Windows_NT 10.0.10586 npm ERR! argv“C:\ Program Files \ nodejs \ node.exe”“C:\ Program Files \ nodejs \ node_modules \ npm \ bin \ npm-cli.js”“ - prefix”“C:\ Users \ TahirAliAwan \ Desktop \功能\功能“”运行“”lint“npm ERR!节点v6.11.5 npm ERR! npm v3.10.10 npm ERR!代码ELIFECYCLE npm ERR!函数@ lint:eslint . 错误的ERR!退出状态1 npm ERR!错误的ERR!函数@ lint script'eslint . '失败 . 错误的ERR!确保安装了最新版本的node.js和npm . 错误的ERR!如果你这样做,这很可能是函数包的问题,npm ERR!不是与npm本身 . 错误的ERR!告诉作者你的系统失败了:npm ERR! eslint . 错误的ERR!您可以使用以下命令获取有关如何为此项目打开问题的信息:npm ERR! npm错误功能npm ERR!或者,如果没有,您可以通过以下方式获取他们的信息:npm ERR! npm所有者ls函数npm ERR!上面可能有额外的日志记录输出 . 错误的ERR!请在任何支持请求中包含以下文件:npm ERR! C:\ Users \ TahirAliAwan \ Desktop \ Function \ npm-debug.log错误:函数预部署错误:命令以非零退出代码1终止

1 回答

  • 0

    在@PeterHaddad提示和我的努力之后,我通过删除此行 .then(response => { console.log('This was the notification Feature'); 并更新nodejs解决了这个问题 . 谢谢大家 .

相关问题