AWS CodeBuild指定Node.js14.x运行时报版本不支持错误咨询
AWS CodeBuild Node.js 14版本适配解决方案
问题根因
你当前使用的aws/codebuild/amazonlinux2-x86_64-standard:3.0构建镜像,最高仅内置支持Node.js 10、12两个版本,无内置Node.js 14运行时包,因此会触发版本不存在的报错。
方案1:升级构建镜像(推荐)
- 进入CodeBuild项目的「环境配置」页面,将原有构建镜像替换为
aws/codebuild/amazonlinux2-x86_64-standard:4.0及更高版本,该系列镜像默认内置Node.js 14运行时 - 修改buildspec配置中
runtime-versions的nodejs值为14,不要带.x后缀,完整配置示例:
version: 0.2 phases: install: runtime-versions: nodejs: 14 build: commands: - node -v # 可选,执行构建前验证Node.js版本是否符合预期 - "npm i" - "npm run build" - "npm run db:migrate" artifacts: files: - "all" - "of" - "our" - "files"
方案2:不更换镜像手动安装Node.js 14
如果因业务限制暂时无法升级构建镜像,可跳过runtime-versions配置,在install阶段直接安装Node.js 14,配置示例:
version: 0.2 phases: install: commands: - curl -sL https://rpm.nodesource.com/setup_14.x | bash - - yum install -y nodejs build: commands: - node -v - "npm i" - "npm run build" - "npm run db:migrate" artifacts: files: - "all" - "of" - "our" - "files"
内容的提问来源于stack exchange,提问作者Ollie
相关产品推荐
相关产品推荐

