【发布时间】:2021-11-13 17:53:20
【问题描述】:
开发人员,我正在尝试将一个简单的云功能部署到 firebase 控制台,一切都运行良好(安装 npm & 配置 & 其他东西......)。
然后我在 index.js 文件中写了一个简单的函数:
'use strict'
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/notififcation/{user_id}/{notififcation_id}').onWrite(
event =>
{
const user_id = event.params.user_id;
const notififcation_id = event.params.notififcation_id;
console.log('this id is the ' , user_id);
}
):
然后,当我想使用此命令 firebase deploy 将其部署到 firebase 时,此错误不断出现, 这是错误:
C:\Users\nasro\Desktop\oussamaproject\notifyfun\functions\index.js
14:2 error Parsing error: Unexpected token :
? 1 problem (1 error, 0 warnings)
npm ERR! code 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! This is probably not a problem with npm. There is likely additional l
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\nasro\AppData\Roaming\npm-cache\_logs\2021-09-19T21_28_2
892Z-debug.log
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "C:\Users\nasro\Desktop\oussamaproject\notifyfun\fun
ions" run lint ENOENT
at notFoundError (C:\Users\nasro\AppData\Roaming\npm\node_modules\firebase
ools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\Users\nasro\AppData\Roaming\npm\node_modules\firebase-
ols\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
at ChildProcess.cp.emit (C:\Users\nasro\AppData\Roaming\npm\node_modules\f
ebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:2
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\nasro\AppData\Roaming\npm\node_modules\f
ebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:3
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix "C:\\Users\\nasro\\Desktop\\oussamaproject\\not
yfun\\functions" run lint',
path: 'npm --prefix "C:\\Users\\nasro\\Desktop\\oussamaproject\\notifyfun\\f
ctions" run lint',
spawnargs: []
}
Error: functions predeploy error: Command terminated with non-zero exit code1
所以在 firebase 文档和文章中搜索解决方案后,我尝试了这些解决方案
解决方案一: 默认在 firebase.json 中:
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
我修改为:
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
该错误再次出现并显示相同的错误消息,所以我尝试了解决方案 2
解决方案二
我再次将文件 firebase.json 修改为:
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
并且错误不断出现,并带有相同的错误消息(btw我使用的是 windows7)
所以对于这个错误的任何解决方案或建议..
【问题讨论】:
标签: node.js firebase google-cloud-functions firebase-cli