下面是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"
},
答案 0 :(得分:1)
我的.gcloudignore中存在问题
以下更改确实有效!
这
node_modules/
到
node_modules