簡體   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