简体   繁体   English

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

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

while deploying pub-sub code on firebase i'm getting following error :在 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) {
          ^

I'm not getting why this error is occurring.我不明白为什么会发生这个错误。

following is the code:以下是代码:

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

I'm going to guess that this function is set to use the Node 8 runtime, since support for async iterators was added in Node 10. The Pub/Sub library has only supported Node 10 and above since 2.0, so bumping the runtime version on the Firebase function should help:我猜这个函数被设置为使用 Node 8 运行时,因为在 Node 10 中添加了对异步迭代器的支持。 Pub/Sub 库自 2.0 以来仅支持 Node 10 及更高版本,因此将运行时版本提高到Firebase 功能应该有助于:

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

Unfortunately I don't have enough points to ask for more details on the original question, but hopefully that helps!不幸的是,我没有足够的分数来询问有关原始问题的更多详细信息,但希望这会有所帮助!

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

相关问题 BaconJS的Pub-Sub - Pub-Sub with BaconJS 部署Firebase云功能时发生意外错误 - Unexpected error while deploying firebase cloud functions 错误:在部署云功能时解析触发器时出错 - Firebase - Error: Error parsing triggers while deploying cloud functions - Firebase 部署 React 时出现错误“路径”参数必须是字符串 - 云函数中的可加载组件示例代码 - Getting error "Path" argument must be string while deploying React - Loadable components sample code in cloud functions 如何从 Firebase Cloud Function 在 Google Pub/Sub 中发布消息? - How to publish message in Google Pub/Sub from Firebase Cloud Function? 为什么要在这里使用Observer / Pub-Sub模式? - Why should we use Observer/Pub-Sub pattern here? 部署Firebase时解析错误 - Parsing error while deploying firebase 获取 `eslint' - 解析错误,同时编译 firebase 云 function - Getting `eslint' - parsing error, while compiling firebase cloud function 在部署 Firebase 云 Function 时收到“每个都应该返回值或抛出”错误 - On Deploying the Firebase Cloud Function getting an error of “Each then should return a value or throw” Pub-Sub 模式和消息代理,如何确保所有订阅者完成对事件的处理 - Pub-Sub pattern and message broker, how to make sure all subscribers finished working on event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM