【问题标题】:cloud build trigger in app engine -Nodejs runtime error应用引擎中的云构建触发器 -Nodejs 运行时错误
【发布时间】:2020-09-03 13:16:09
【问题描述】:

警告:您的 package.json 未指定受支持的 Node.js 版本。请将您的应用程序固定到 Node.js 运行时的主要版本。

应用程序检测失败:错误:node.js 检查器:“package.json”的“scripts”部分中的“start”和“server.js”文件均未找到。

我在 package.json 下面添加了 “引擎”: { “节点”:“^13.8.0”, "npm":"^6.13.4" }, app.yaml 文件

 # [START runtime]
    runtime: nodejs
    env: flex
    service: dev
    
    handlers:
    - url: /.*
      secure: always
      script: auto
      redirect_http_response_code: 301
    
    automatic_scaling:
      min_num_instances: 1
      max_num_instances: 2
      cool_down_period_sec: 60
      cpu_utilization:
        target_utilization: 0.80

package.json

"scripts": {
        "start": "serve -s ./build",
        "prestart": "npm i -g serve",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    }

cloudbuild.yaml

steps:

- name: gcr.io/cloud-builders/npm
  entrypoint: 'npm'
  args: [ install ]

- name: gcr.io/cloud-builders/npm
  entrypoint: 'npm'
  args: [ run, build, --prod ]


- name: gcr.io/cloud-builders/gcloud
  entrypoint: 'npm'
  args: [ app, deploy, '[public/app.yaml]', --version=$SHORT_SHA ]

【问题讨论】:

  • 你解决了吗?我有同样的问题。我有 package.json 文件,它也有启动脚本。但我仍然遇到同样的错误

标签: node.js google-app-engine runtime


【解决方案1】:

如果您使用的是 GAE 标准,请记住它目前支持 Node.js 10 和 12 runtimes

另外,正如官方 GCP documentation 提到的那样:

默认情况下,运行时通过运行节点来启动您的应用程序 server.js。如果您在 package.json 文件中指定启动脚本, 运行时运行指定的启动脚本。

"scripts": {
  "start": "node app.js"
}

请查看this GitHub 存储库,其中包含一个适用于 GAE 标准的简单应用程序,您可以将其用作参考。


编辑

您需要确保您的启动脚本正在启动一个 Web 服务器,该服务器在 PORT 环境变量指定的端口上响应 HTTP 请求,通常是 8080 (link)。

Here你可以看到一个GAE柔性环境的例子,其中app.js包含

// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');
});

虽然 package.json

"scripts": {
    "start": "node app.js"
}

deploying 在 GAE 上使用 Cloud Build 删除启动脚本或应用未启动服务器时,此错误可能会重现。

【讨论】:

  • 我用上面的代码更改了 pacakge.json"engines": { "node": "^12.0.0", "npm":"^6.13.4" } 但我还是一样错误 app.yaml 文件应该做任何更改吗?
  • 你得到的错误是Neither "start" in the "scripts" section of "package.json" nor the "server.js" file were found。您可以尝试在我链接的 GCP 文档中提到的 package.json 文件中添加启动脚本吗?
  • 如果没有帮助,请更新您的问题,添加 package.jsonapp.yaml 文件的内容,以及您的应用程序的最小可重现代码。请记住删除这些文件可能包含的任何敏感信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-18
  • 2022-06-15
  • 2021-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多