aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
175 stars 61 forks source link

[Astro build] CustomerError: The size of the build output (424304711) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src1007620978/src/xxx/.amplify-hosting/compute/default) and try again. #2189

Open akila-ocj opened 3 days ago

akila-ocj commented 3 days ago

Environment information

I am trying to deploy below template using AWS amplify: https://astro.build/themes/details/copper-astro/. My build output is approximately 424 MB, exceeding the limit of 220 MB. I am reporting this as a bug since I cannot control the max allowed size in Amplify.

I followed the steps in the aws doc to deploy the web app: https://docs.aws.amazon.com/amplify/latest/userguide/get-started-astro.html

The instruction in the above aws doc:

In the amplify.yml file, locate the frontend build commands section. Enter mv node_modules ./.amplify-hosting/compute/default

causes an error due to the max allowed size of 230686720 bytes.

Build image: Amazon Linux 2023

amplify.yml:
version: 1
frontend:
    phases:
        preBuild:
            commands:
                - 'npm ci --cache .npm --prefer-offline'
        build:
            commands:
                - 'npm run build'
                - 'mv node_modules ./.amplify-hosting/compute/default'
    artifacts:
        baseDirectory: .amplify-hosting
        files:
            - '**/*'
    cache:
        paths:
            - '.npm/**/*'

Describe the bug

Below is the deployment log:

2024-11-03T00:28:54.805Z [INFO]: 24:28:54 ✓ Completed in 3.98s.

234

2024-11-03T00:28:54.829Z [INFO]: 24:28:54 [@astrojs/sitemap] `sitemap-index.xml` created at `dist`

235

2024-11-03T00:28:54.830Z [INFO]: 24:28:54 [build] 29 page(s) built in 15.72s

236

24:28:54 [build] Complete!

237

2024-11-03T00:28:54.874Z [INFO]: # Executing command: mv node_modules ./.amplify-hosting/compute/default

238

2024-11-03T00:28:54.876Z [INFO]: # Completed phase: build

239

## Completed Frontend Build

240

2024-11-03T00:28:54.886Z [INFO]: ## Build completed successfully

241

2024-11-03T00:28:54.887Z [INFO]: # Starting caching...

242

2024-11-03T00:28:54.895Z [INFO]: # Creating cache artifact...

243

2024-11-03T00:28:54.898Z [INFO]: # Created cache artifact

244

2024-11-03T00:28:54.898Z [INFO]: # Uploading cache artifact...

245

2024-11-03T00:28:54.963Z [INFO]: # Uploaded cache artifact

246

2024-11-03T00:28:54.963Z [INFO]: # Caching completed

247

2024-11-03T00:29:13.700Z [ERROR]: !!! CustomerError: The size of the build output (424304711) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src1007620978/src/palxi2/.amplify-hosting/compute/default) and try again.

248

2024-11-03T00:29:13.804Z [INFO]: # Starting environment caching...

249

2024-11-03T00:29:13.804Z [INFO]: # Environment caching completed

Reproduction steps

Hosting the same website on amplify using the aws docs. Its a paid template I already downloaded it happy to email you the template if you need it.

Jay2113 commented 1 day ago

Hi @akila-ocj 👋 , thanks for reaching out. You've correctly stated that this issue occurs since the build output size exceeds 220 MB due to the size of the node_modules being copied over to the .amplify-hosting/compute/default directory. In the long term, to mitigate it the process of copying over the node_modules will need to be optimized and tree shaking will need to be implemented.

In the short term, our recommendation will be to review this troubleshooting guide and manually remove the binaries or node_modules that aren't required at runtime.

After downloading the build artifacts, you can review the dependencies locally:

- cd compute/default/node_modules
- du -csh *

Identify dependencies that you can remove

Next, modify the amplify.yml to remove them at buildtime:

build:
      commands:
        - npm run build
        - npm prune --omit=dev --omit=optional
        - rm -rf node_modules/{deps1}
        - rm -rf node_modules/{deps2}
        - mv node_modules ./.amplify-hosting/compute/default