I'm trying to deploy my React application through AWS codepipeline and codebuild.
However, codebuild failed with below error:
[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 [email protected]: 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.
I don't know why codebuild picked 10.19.0 here.
I'm using yarn build to build package. I can run the app with yarn start without problem locally.
Here is my 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/**/*"
I also specified the node version in package.json:
"name": "my-package",
"version": "0.1.0",
"private": true,
"engines": {
"node": ">=14.0.0",
"npm": ">=8.5.5"
},
I'm able to solve the issue based on fedonev@'s answer.
As he said, I need configure the build image to use CodeBuild.LinuxBuildImage.STANDARD_5_0 in CodeBuild Project.
// 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],
}),
],
});
You must also configure the CodeBuild Project to use a build image that supports the Nodejs v14 runtime. The Ubuntu Standard 5 image is the only image that does at the moment. In CloudFormation:
Type: AWS::CodeBuild::Project
Properties:
Environment:
Image: "aws/codebuild/standard:5.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With