如何在代码构建的构建规范中将 nodejs 文件更改为 14?

How to change nodejs file to 14 in buildspec for codebuild?

这是我的 buildspec.yml codebuild 使用的文件:

version: 0.2
env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 14
   pre_build:
    commands:
      - echo Installing source NPM dependencies...
      - npm install -g aws-cdk
      - npm install -g typescript
      - npm install
      - npm run build 

  build:
    commands:
      - cdk --version 
      - cdk ls
      - cdk synth 
  post_build:

/usr/local/bin/cdk -> /usr/local/lib/node_modules/aws-cdk/bin/cdk npm WARN notsup Unsupported engine for aws-cdk@2.9.0: wanted: {"node":">= 14.15.0"} (current: {"node":"12.22.2","npm":"6.14.13"}) npm WARN notsup Not compatible with your version of node/npm: aws-cdk@2.9.0

最后,cdk ls 失败了

感谢任何帮助,因为我已经尝试删除节点模块和包-lock.json。

除了设置buildspec中的runtime-version,设置CodeBuildProjectenvironment prop to a build image type that supports Node 14。目前,只有 Ubuntu Standard:5 可以。

new codebuild.Project(this, 'MyBuildProject', {
  environment: {
    buildImage: codebuild.LinuxBuildImage.STANDARD_5_0,
  },
  buildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    phases: {
      install: {
        'runtime-versions': {
          nodejs: '14.x',
        },