繁体   English   中英

eslint引发错误

[英]eslint throws error

我是新来的android初学者,并尝试部署firebase函数,但显示一些错误如何解决此问题,请帮助我。

Firebase数据库结构

用户表

  • 用户数
    • 用户身份
      • device_token:user_device_token
      • 名称:user_name

通知表

  • 通知
    • to_user_id
      • notification_id
        • 来自:from_user_id

错误

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%运行lint函数@ lint C:\\ Users \\ TahirAliAwan \\ Desktop \\ Function \\ functions eslint。 C:\\ Users \\ TahirAliAwan \\ Desktop \\ Function \\ functions \\ index.js 61:11警告避免嵌套promise promise /不嵌套84:14警告避免嵌套promise promise / nonested 84:69错误每个then()应该返回值或抛出承诺/始终返回✖3个问题(1个错误,2个警告)npm ERR! Windows_NT 10.0.10586 npm错误! argv“ C:\\ Program Files \\ nodejs \\ node.exe”“ C:\\ Program Files \\ nodejs \\ node_modules \\ npm \\ bin \\ npm-cli.js”“-前缀”“ C:\\ Users \\ TahirAliAwan \\ Desktop \\ Function \\ functions“” run“” lint“ npm ERR! 节点v6.11.5 npm ERR! npm v3.10.10 npm错误! 代码ELIFECYCLE npm ERR! functions @ lint: eslint . npm ERR! 退出状态1 npm ERR! npm ERR! 在functions @ lint脚本“ eslint”处失败。 npm ERR! 确保已安装最新版本的node.js和npm。 npm ERR! 如果这样做,这很可能是功能包npm ERR的问题! 不与npm本身。 npm ERR! 告诉作者这在您的系统上失败:npm ERR! 埃斯林特。 npm ERR! 您可以通过以下方式获取有关如何为此项目打开问题的信息:npm ERR! npm错误功能npm错误! 或者,如果不可用,则可以通过以下方式获取其信息:npm ERR! npm owner ls函数npm ERR! 上面可能还有其他日志记录输出。 npm ERR! 请在支持请求中包含以下文件:npm ERR! C:\\ Users \\ TahirAliAwan \\ Desktop \\ Function \\ npm-debug.log错误:函数预部署错误:命令以非零退出代码终止

在@PeterHaddad技巧和我的努力之后,我通过删除此行.then(response => { console.log('This was the notification Feature'); is .then(response => { console.log('This was the notification Feature');并更新了nodejs。解决了所有问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM