Firebase函数-https onRequest“ HTTP错误:400,请求有错误”

时间:2019-06-22 16:16:26

标签: node.js typescript firebase express google-cloud-functions

我的firebase函数遇到一些重大问题。我正在尝试创建一个https请求,以便可以将数据发送到Firebase。

我有一个非常简单的代码可以测试,并且会导致错误:

这是我的代码(此代码应该没有问题):

exports.fetchPosts = functions.https.onRequest((req, res) => {
    console.log(req)
    res.send("Hello!")
})

我的index.ts文件长700行。.如果没有fetchPosts,它的部署就很好。.使用fetchPosts我会得到这些错误。.

这是错误:

  

!函数:无法创建函数fetchPosts

     

HTTP错误:400,请求有错误

这是详细的错误消息:

  

[2019-06-22T16:09:13.362Z] <<< HTTP RESPONSE 400 variant = X来源,引荐来源网址,来源,接受编码,content-type = application / json; charset = UTF-8,date = Sat,22 Jun 2019 16:09:11 GMT,server = ESF,cache-control = private,x-xss-protection = 0,x-frame-options = SAMEORIGIN,x-content- type-options = nosniff,alt-svc = quic =“:443”; ma = 2592000; v =“ 46,44,43,39”,accept-ranges = none,connection = close   [2019-06-22T16:09:13.362Z] <<< HTTP响应代码= 400,消息=请求有错误,状态= INVALID_ARGUMENT,详细信息= [@ type = type.googleapis.com / google.rpc.BadRequest ,fieldViolations = [字段=运行时,描述=运行时字段不能为空。]]   !函数:无法创建函数fetchPosts   HTTP错误:400,请求有错误

任何想法可能是什么问题?这似乎很荒谬,因为从字面上看应该起作用。

1 个答案:

答案 0 :(得分:0)

几周后设法解决了这个问题!!终于对我有用的:

  • npm i -g firebase-tools@latest
  • 已删除的package-lock.json文件
  • 已删除的node_modules文件夹
  • npm install
  • firebase deploy

希望可以帮助处于同一职位的人!