【问题标题】:gCloud: File index.js does not exist in root directorygCloud:根目录中不存在文件 index.js
【发布时间】:2018-01-01 05:14:38
【问题描述】:

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

gcloud beta functions deploy FirstBot --stage-bucket [BUCKET_NAME] --trigger-http

我在我的 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.

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

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

这是第二个:

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

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

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

请帮助..不胜感激!

【问题讨论】:

  • 随着调查的继续,您不应该完全改变问题的上下文 - 使一切无效...而是提出一个新问题,最终将原始问题作为上下文引用。
  • 你能解决这个问题吗?如果是这样,建议发布您的答案作为更好地帮助社区的解决方案。如果您仍然遇到问题,建议您运行“gcloud components update”以安装最新的 GCloud 并关注deployment guide

标签: google-cloud-datastore google-cloud-platform gcloud


【解决方案1】:

文件在您的.gitignore 中吗? If a .gcloudignore isn't specified, the .gitignore is used to ignore files.

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

【讨论】:

    【解决方案2】:

    如果您没有从 index.js 所在的同一文件夹运行部署命令,也会发生该错误。 IE。只是“找不到文件”。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        您超出了Max deployment size 的限制。来自Resource Limits

        检查你的项目目录的内容,你可能有不想要的东西。

        【讨论】:

        • 嘿,丹!我的项目目录路径是 C:\FirstBot 它只有 1 个 index.js 文件
        • 尝试使用--verbosity=debug(或info?)来提高cmd的详细程度,也许日志会显示该大小来自哪里。
        • 嘿,所以我进入我的 FirstBot 目录并运行命令: C:\FirstBot>gcloud beta functions deploy FirstBot --stage-bucket supple-cheme-648 --trigger-http 并且它是给我这个错误:部署功能(可能需要一段时间 - 最多 2 分钟)...失败。 ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function l 加载错误:根目录中不存在预期定义函数的文件index.js或function.js。跨度>
        • 您能否发布index.js 文件的内容(或者至少是FirstBothelloHttp 函数)?
        【解决方案5】:

        通过控制台向项目添加存储桶为我解决了这个问题。

        【讨论】:

          【解决方案6】:

          命令gcloud beta functions deploy FirstBot --stage-bucket [BUCKET_NAME] --trigger-http 将部署一个名为FirstBot 的函数,方法是创建包含运行命令的目录内容的zip 文件。

          为了使部署正常工作,您应该:

          • C:\FirstBot 中运行命令,或者
          • --source C:\FirstBot 添加到您的 gcloud 调用中,让 gcloud 知道您的源代码位于不同的目录中。

          【讨论】:

          • 嘿!我从一开始就从 C:\FirstBot 运行命令,但我收到了问题中描述的错误!
          • 您可以尝试使用--local-path 标志运行它吗?如果没有帮助,您可以下载 gcloud 上传的 zip 文件并查看其内容是否为 C:\FirstBot
          • --local-pathgcloud functions deploygcloud beta functions deploy 中似乎不可用
          • --local-path 标志已替换为 --source ,因为我写了那个答案。我会编辑答案。
          【解决方案7】:

          II 遇到了类似的问题,对我来说解决方案很容易应用但很难找到。 万一有人可以帮忙。我注意到我的 .gcloudignore 有这一行

          #!include:.gitignore

          还有我的 .gitignore 这两个

          # Compiled JavaScript files    
          **/*.js
          **/*.js.map
          

          因此 .js 文件被忽略并且 gcloud 找不到 index.js。

          由于我不希望已编译的文件位于存储库中,因此我通过删除 .gcloudignore 中的包含并直接添加特定的忽略来结束,例如 node_modules 和敏感数据

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-04-01
            • 1970-01-01
            • 1970-01-01
            • 2014-06-02
            • 1970-01-01
            • 1970-01-01
            • 2011-12-12
            • 1970-01-01
            相关资源
            最近更新 更多