部署firebase云发布子代码时出错

7gcisfzg  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(222)

在firebase上部署发布子代码时,我遇到以下错误:

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);
  }
};

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题