具有依赖关系的Gcloud后台函数无法部署

时间:2018-03-12 10:48:00

标签: google-cloud-functions google-cloud-pubsub serverless

下面是gcloud后台函数的基本示例,其中包含依赖项。在使用uuid包时,虽然package.json具有uuid

,但它会引发错误

接收部署以下错误。

gcloud beta functions deploy helloPubSub --trigger-resource my-topic --trigger-event google.pubsub.topic.publish

ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'uuid'

index.js

const uuid = require('uuid');

exports.helloPubSub = (event, callback) => {

  const pubsubMessage = event.data;

  const eventName = pubsubMessage.data ? Buffer.from(pubsubMessage.data, 'base64').toString() : 'World';

  console.log(eventName,uuid.v4());

  callback();

};

的package.json

  "dependencies": {
    "uuid": "^3.2.1"
  },

1 个答案:

答案 0 :(得分:1)

我的.gcloudignore中存在问题

以下更改确实有效!

node_modules/

node_modules