繁体   English   中英

部署 Firebase 云发布订阅代码时出错

[英]getting error while deploying firebase cloud pub-sub code

在 firebase 上部署 pub-sub 代码时,我收到以下错误:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. This is likely due to a bug in the user code. Error message: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /srv/node_modules/@google-cloud/pubsub/build/src/pubsub.js:527
    async *listSchemas(view = schema_1.SchemaViews.Basic, options) {
          ^

我不明白为什么会发生这个错误。

以下是代码:

exports.publish = async (req, res) => {
  if (!req.body.topic || !req.body.message) {
    res.status(400).send('Missing parameter(s); include "topic" and "message" properties in your request.');
    return;
  }

  console.log(`Publishing message to topic ${req.body.topic}`);

  const topic = pubsub.topic(req.body.topic);

  const messageObject = {
    data: {
      message: req.body.message,
    },
  };
  const messageBuffer = Buffer.from(JSON.stringify(messageObject), "utf8");

  try {
    await topic.publish(messageBuffer);
    res.status(200).send("Message published.");
  } catch (err) {
    console.error(err);
    res.status(500).send(err);
    return Promise.reject(err);
  }
};

我猜这个函数被设置为使用 Node 8 运行时,因为在 Node 10 中添加了对异步迭代器的支持。 Pub/Sub 库自 2.0 以来仅支持 Node 10 及更高版本,因此将运行时版本提高到Firebase 功能应该有助于:

https://firebase.google.com/docs/functions/manage-functions#set_nodejs_version

不幸的是,我没有足够的分数来询问有关原始问题的更多详细信息,但希望这会有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM