開發者們,我正試圖將一個簡單的云功能部署到firebase控制臺,一切都很順利(安裝npm&;配置&;其他東西...)。
然后我在index.js檔案中寫了一個簡單的函式:
'use strict'。
const functions = require("firebase-functions")。
const admin = require('firewase-admin')。
admin.initializeApp(function.config().firebase) 。
exports.sendNotification = functions.database. ref('/notifcation/{user_id}/{notifcation_id}'/span>).onWrite(
event =>/span>
{
const user_id = event.params.user_id。
const notififcation_id = event.params.notifcation_id。
console.log('this id is the ' , user_id) 。
}
):
然后,當我想用這個命令firebase deploy將其部署到firebase時,這個錯誤一直出現。 這就是錯誤所在:
C:Users
js otifyfunfunctionsindex.php?
14:2錯誤Parsing error。Unexpected token :
? 1問題(1錯誤,0警告)。
npm ERR! 代碼 ELIFECYCLE!
npm ERR! errno 1!
npm ERR! functions@ lint: `eslint .`!
npm ERR! Exit status 1!
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! 這可能不是一個問題與npm。有可能是額外的l
ging輸出。
npm ERR! 一個完整的日志of this run可以在in找到。
npm ERR! C:Users!
asroAppDataRoaming。
pm-cache\_logs2021-09-19T21_28_2
892Z-debug.log。
events.js:292
throw er; //未處理的'錯誤'事件。
^
Error: spawn npm --prefix "C:Users
asroDesktopoussamaproject
的通知
ions"運行lint ENOENT。
at notFoundError (C:Users)
asroAppDataRoaming
滑鼠
ode_modulesfirebase
ools
ode_modulescross-env
ode_modulescross-spawnlibenoent.js:6:26)
at verifyENOENT (C:Users)
asroAppDataRoaming。
滑鼠
ode_modulesfirebase
串列
ode_modulescross-env
ode_modulescross-spawnlibenoent.js:40:16)
在ChildProcess.cp.emit(C:Users)
asroAppDataRoaming
滑鼠
指南針_modulesf
ebase-tools
ode_modulescross-env
ode_modulescross-spawnlibenoent.js:27:2
在Process.ChildProcess._handle。 onexit (internal/child_process.js:275:12)
Emitted 'error'事件在ChildProcess實體at。
在ChildProcess.cp.emit (C:Users)
asroAppDataRoaming
滑鼠
指南針_modulesf
ebase-tools
ode_modulescross-env
ode_modulescross-spawnlibenoent.js:30:3。
在Process.ChildProcess._handle。 onexit (internal/child_process.js:275:12)
code: 'ENOENT'。
errno: 'ENOENT',
syscall: 'spwn npm --preix "C:Users
asroDesktopoussamaproject
ot
yfunfunctions" run lint'。
path。'npm --preix "C:Users
asroDesktopoussamaproject
otifyfunf
ctions" run lint'。
spawnargs。[]
}
Error: functions predeploy error: Command terminated with non-zero exit code1
所以在Firebase檔案和文章中尋找解決方案后,我嘗試了這些解決方案
解決方案一: 在firebase.json中默認:"predeploy"/span>: [
"npm --prefix "$RESOURCE_DIR" run lint"。
我把它修改為:
"predeploy": [
"npm --prefix "%RESOURCE_DIR%" run lint"。
錯誤不斷出現,而且是同樣的錯誤資訊,所以我嘗試了解決方案二
解決方案二我再次修改了檔案firebase.json為:
"predeploy"/span>: [
"npm --prefix "%RESOURCE_DIR%" run lint"。
"npm --prefix "%RESOURCE_DIR%" run build"。
]
而且這個錯誤不斷出現,并帶有相同的錯誤資訊(btw我使用的是windows7)
那么對于這個錯誤有什么解決辦法或建議嗎?
uj5u.com熱心網友回復:
看起來你的函式以冒號而不是分號結束。把它改成這樣:
"use strict"。
const functions = require("firewase-functions")。
const admin = require("firewase-admin")。
admin.initializeApp(function.config().firebase) 。
exports.sendNotification = functions.database。
.ref("/notifcation/{user_id}/{notifcation_id}"/span>)
.onWrite((change, context) =>/span> {
const userId = context.params.user_id。
// const notifcationId = context.params.notifcation_id;.
console.log("this id is the", userId)。
}
);
uj5u.com熱心網友回復:
onWrite方法需要2個引數 - change和context,引數在context物件上。
你能不能試試下面的方法:
functions.database.ref("/notififcation/{user_id}/{notifcation_id}"/span>) 。 onWrite((change, context) =>{
const user_id = context.params.user_id。
const notififcation_id = context.params.notifcation_id。
console.log("this id is the" , user_id)。
return null; // <----- 請嘗試在最后也回傳一些東西。
});
更多資訊在這里 - https://firebase.google.com/docs/functions/database-events#reading_the_previous_value
似乎還有一個問題,那就是在你下面的評論中出現了提示錯誤,也許可以嘗試更新你專案中的.eslintrc.js或.eslintrc.json檔案,像這樣:
module.exports = {
root: true,
env: { es6: true, node: true, },
extends: ["eslint:recommended"], // <--從這里洗掉google。
rules: { quotes: ["error", "double"], }; border="0"。
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/325766.html
標籤:
