简体   繁体   English

eslint引发错误

[英]eslint throws error

i am new android beginner and try to deploy firebase functions but show some error how to solve this problem plz help me. 我是新来的android初学者,并尝试部署firebase函数,但显示一些错误如何解决此问题,请帮助我。

Firebase database structure Firebase数据库结构

User Table 用户表

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

Notification Table 通知表

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

Error 错误

Index.js 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 show error ** ** cmd显示错误**

C:\\Users\\TahirAliAwan\\Desktop\\Function>firebase deploy === Deploying to 'videochat-96f75'... i deploying functions Running command: npm --prefix %RESOURCE_DIR% run lint functions@ lint C:\\Users\\TahirAliAwan\\Desktop\\Function\\functions eslint . 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 warning Avoid nesting promises promise/no-nesting 84:14 warning Avoid nesting promises promise/no-nesting 84:69 error Each then() should return a value or throw promise/always-return ✖ 3 problems (1 error, 2 warnings) npm ERR! 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 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" "--prefix" "C:\\Users\\TahirAliAwan\\Desktop\\Function\\functions" "run" "lint" npm ERR! 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! node v6.11.5 npm ERR! 节点v6.11.5 npm ERR! npm v3.10.10 npm ERR! npm v3.10.10 npm错误! code ELIFECYCLE npm ERR! 代码ELIFECYCLE npm ERR! functions@ lint: eslint . functions @ lint: eslint . npm ERR! npm ERR! Exit status 1 npm ERR! 退出状态1 npm ERR! npm ERR! npm ERR! Failed at the functions@ lint script 'eslint .'. 在functions @ lint脚本“ eslint”处失败。 npm ERR! npm ERR! Make sure you have the latest version of node.js and npm installed. 确保已安装最新版本的node.js和npm。 npm ERR! npm ERR! If you do, this is most likely a problem with the functions package, npm ERR! 如果这样做,这很可能是功能包npm ERR的问题! not with npm itself. 不与npm本身。 npm ERR! npm ERR! Tell the author that this fails on your system: npm ERR! 告诉作者这在您的系统上失败:npm ERR! eslint . 埃斯林特。 npm ERR! npm ERR! You can get information on how to open an issue for this project with: npm ERR! 您可以通过以下方式获取有关如何为此项目打开问题的信息:npm ERR! npm bugs functions npm ERR! npm错误功能npm错误! Or if that isn't available, you can get their info via: npm ERR! 或者,如果不可用,则可以通过以下方式获取其信息:npm ERR! npm owner ls functions npm ERR! npm owner ls函数npm ERR! There is likely additional logging output above. 上面可能还有其他日志记录输出。 npm ERR! npm ERR! Please include the following file with any support request: npm ERR! 请在支持请求中包含以下文件:npm ERR! C:\\Users\\TahirAliAwan\\Desktop\\Function\\npm-debug.log Error: functions predeploy error: Command terminated with non-zero exit code1 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