[AWS CodeBuild]引擎 "node" 与此模块不兼容。预期版本“>=14.0.0”。得到“10.19.0”

[AWS CodeBuild]The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "10.19.0"

我正在尝试通过 AWS codepipeline 和 codebuild 部署我的 React 应用程序。

但是,代码构建失败并出现以下错误:

[Container] 2022/04/19 02:42:19 Waiting for agent ping
[Container] 2022/04/19 02:42:29 Waiting for DOWNLOAD_SOURCE
[Container] 2022/04/19 02:42:30 Phase is DOWNLOAD_SOURCE
[Container] 2022/04/19 02:42:30 CODEBUILD_SRC_DIR=/codebuild/output/src234015054/src
[Container] 2022/04/19 02:42:30 YAML location is /codebuild/output/src234015054/src/buildspec.yml
[Container] 2022/04/19 02:42:30 Processing environment variables
[Container] 2022/04/19 02:42:30 [WARN] Skipping install of runtimes. Runtime version selection is not supported by this build image.
[Container] 2022/04/19 02:42:33 Moving to directory /codebuild/output/src234015054/src
[Container] 2022/04/19 02:42:33 Expanded cache path ./node_modules/**/*
[Container] 2022/04/19 02:42:33 Configuring ssm agent with target id: codebuild:0a77403f-035c-4d62-b96e-de5449f7f4bc
[Container] 2022/04/19 02:42:33 Successfully updated ssm agent configuration
[Container] 2022/04/19 02:42:33 Registering with agent
[Container] 2022/04/19 02:42:33 Phases found in YAML: 2
[Container] 2022/04/19 02:42:33  INSTALL: 2 commands
[Container] 2022/04/19 02:42:33  BUILD: 1 commands
[Container] 2022/04/19 02:42:33 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2022/04/19 02:42:33 Phase context status code:  Message: 
[Container] 2022/04/19 02:42:33 Entering phase INSTALL
[Container] 2022/04/19 02:42:33 Running command echo Performing yarn install
Performing yarn install

[Container] 2022/04/19 02:42:33 Running command yarn install
yarn install v1.22.4
[1/5] Validating package.json...
error website@0.1.0: The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "10.19.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

我不知道为什么codebuild在这里选择了10.19.0

更多信息

我正在使用 yarn build 构建包。我可以 运行 使用 yarn start 的应用程序在本地没有问题。

这是我的 buildspec.yml:

version: 0.2
phases:
  install:
    runtime-versions:
      nodejs: 14
    commands:
      - echo Performing yarn install
      - yarn install
  build:
    commands:
      - yarn build

artifacts:
  base-directory: ./build
  files:
    - "**/*"

cache:
  paths:
    - "./node_modules/**/*"

我也在package.json中指定了节点版本:

 "name": "my-package",
  "version": "0.1.0",
  "private": true,
  "engines": {
    "node": ">=14.0.0",
    "npm": ">=8.5.5"
  },

更新解决方案

我可以根据fedonev@的回答解决问题。

正如他所说,我需要配置构建映像以在 CodeBuild 项目中使用 CodeBuild.LinuxBuildImage.STANDARD_5_0

// AWS CodePipeline stage to build website
pipeline.addStage({
  stageName: "Build",
  actions: [
    // AWS CodePipeline action to run CodeBuild project
    new codepipeline_actions.CodeBuildAction({
      actionName: "BuildeWebsite",
      project: new CodeBuild.PipelineProject(this, "BuildWebsite", {
        projectName: "BuildeWebsite",
        environment: {
          buildImage: CodeBuild.LinuxBuildImage.STANDARD_5_0
        },
        buildSpec:
          CodeBuild.BuildSpec.fromSourceFilename("./buildspec.yml"),
      }),
      input: outputSources,
      outputs: [outputWebsite],
    }),
  ],
});

您还必须将 CodeBuild 项目配置为使用 build image that supports the Nodejs v14 runtime。 Ubuntu 标准 5 图像是目前唯一可用的图像。在 CloudFormation 中:

Type: AWS::CodeBuild::Project
Properties: 
  Environment:
    Image: "aws/codebuild/standard:5.0"