ng build fail at codeBuild with 'Javascript out of heap memory' in AWS
Asked Answered
P

2

2

I am using AWS code-build for my angular-7 project. I install AWS-amplify in the existing project than when I build the AWS service (codeBuild) I got the following error.

ng build --prod: Javascript out of heap memory

The local build is run successfully but doesn't know the real reason behind the failure in the pipeline (codeBuild) phase.

Tried some help from StackOverflow as well like this question but all in vain. Any idea why the AWS code-build having this issue rather than a local one and solution to get away from this problem. Thanks

Phytogenesis answered 8/10, 2021 at 20:31 Comment(0)
P
9

After much researches from AWS docs and forums. Got the below solutions which are as below.

  1. Add memory in ENV variable of code-build

    • Open the CodeBuild service and open your project.

    • Click on the build details and there will be a section of environment variables.

    • Edit the ENV variables and in additional configuration add the below value as per your requirement.

    enter image description here

    The value which shown in picture is --max_old_space_size=4096.

  2. Increase the Compute value as required.

    • Follow the above steps to reach the additional configuration and change the compute value as you need.

Phytogenesis answered 11/10, 2021 at 10:25 Comment(1)
Thanks! FYI. I also had to uncheck the "Allow AWS Code Build to modify..." per this post: https://mcmap.net/q/611524/-unable-to-update-service-role-in-codebuild-with-error-quot-the-policy-was-not-attached-to-role-quotSullyprudhomme
Z
1

If you are using AWS CDK, you can change the default compute type on the Code Pipeline object.

TypeScript example:

const pipeline = new CodePipeline(this, 'Pipeline', {
    codeBuildDefaults: {
        buildEnvironment: {
            computeType: ComputeType.MEDIUM,
        },
    },
});

The options are:

  • SMALL (default)
  • MEDIUM
  • LARGE
  • X2_LARGE

You can find more info about the options on the docs: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.ComputeType.html

Zug answered 10/1, 2022 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.