gCloud:根目录中不存在文件index.js

Mav*_*ck7 5 google-cloud-datastore google-cloud-platform gcloud

我是 Gcloud 的第一次用户。当我运行以下命令时:

gcloud beta functions deploy FirstBot --stage-bucket [BUCKET_NAME] --trigger-http
Run Code Online (Sandbox Code Playgroud)

我在 cmd 中收到此错误:

ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function l
oad error: File index.js or function.js that is expected to define function does
n't exist in the root directory.
Run Code Online (Sandbox Code Playgroud)

我尝试了 2 个 index.js 文件:这是第 1 个:

   /*
 HTTP Cloud Function.

 @param {Object} req Cloud Function request context.
 @param {Object} res Cloud Function response context.
*/
exports.FirstBot = function FirstBot (req, res) {
  response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working

res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
  res.send(JSON.stringify({ "speech": response, "displayText": response 
  //"speech" is the spoken version of the response, "displayText" is the visual version
  }));
};
Run Code Online (Sandbox Code Playgroud)

这是第二个:

/
 HTTP Cloud Function.

 @param {Object} req Cloud Function request context.
 @param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
  response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working

res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
  res.send(JSON.stringify({ "speech": response, "displayText": response 
  //"speech" is the spoken version of the response, "displayText" is the visual version
  }));
};
Run Code Online (Sandbox Code Playgroud)

我的项目名称是FirstBot。我也创建了一个桶。

我的 FirstBot 文件夹的路径是 C:\FirstBot。index.js 文件位于其中。我正在关注以下教程:https ://api.ai/docs/getting-started/basic-fulfillment-conversation

请帮忙..将不胜感激!

0xc*_*aff 5

文件在你的吗.gitignore如果.gcloudignore未指定 a,则.gitignore使用 the 来忽略文件。

添加一个空.gcloudignore应该可以解决这个问题。


Mav*_*ck7 1

我通过安装 JavaScript 的 npm 解决了这个问题。