astro-aws-amplify icon indicating copy to clipboard operation
astro-aws-amplify copied to clipboard

getting too much size of build

Open TheElegantCoding opened this issue 1 year ago • 16 comments

adding mv node_modules ./.amplify-hosting/compute/default is not the correct way to add the adapter you can get this The size of the build output (297310198) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output

TheElegantCoding avatar May 13 '24 13:05 TheElegantCoding

Hi thanks for reporting.

I see, due to the way pnpm works, I think it should get around that issue if you're willing to switch to it. Otherwise feel free to make a PR for any better solutions as I'm unsure of any. Cheers.

alexnguyennz avatar May 13 '24 19:05 alexnguyennz

Hi guys. Did you find a solution? I have the same problem. Thanks!

tonicastillo avatar May 31 '24 08:05 tonicastillo

Hi guys. Did you find a solution? I have the same problem. Thanks!

Hi do you have a project I can look at?

alexnguyennz avatar May 31 '24 19:05 alexnguyennz

In the end I was able to transfer some libraries to dev, and it stopped giving me problems. Thank you anyway.

tonicastillo avatar Jun 04 '24 09:06 tonicastillo

i actually use bun to install dependencies not sure if that can be the problem, @alexnguyennz can you update the readme and make a test with bun ?

also here thinking about something the 404 page can be done with .htaccess ?, i remember fix in some project this

# Custom error pages
ErrorDocument 404 /404.html

TheElegantCoding avatar Jun 04 '24 14:06 TheElegantCoding

I wasn't aware Bun could be used with Amplify - what sort of build spec are you using? I see now Bun can be used with Windows so I could try this.

Searching htaccess with Amplify doesn't seem to have any results unfortunately, except for this post saying it's not used.

alexnguyennz avatar Jun 05 '24 08:06 alexnguyennz

this is my configuration to set my environment normally, i don't run astro with Bun because is still experimental and don't want some unexpected errors, in linex environment i use the same linux 2023

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - nvm install 20.10.0
        - nvm use 20.10.0
        - npm i -g pnpm
        - npm install -g bun
        - bun i
    build:
      commands:
        - pnpm build
  artifacts:
    baseDirectory: dist
    files:
      - '**/*'
cache:
  paths:
    - node_modules/**/*

TheElegantCoding avatar Jun 05 '24 12:06 TheElegantCoding

Hello! It's Erik from AWS Amplify. We have a troubleshooting guide if your bundle size is over the 220mb limit. https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html#build-output-too-large

ErikCH avatar Jun 11 '24 23:06 ErikCH

Thanks Erik, this is helpful.

alexnguyennz avatar Jun 12 '24 00:06 alexnguyennz

I was able to reduce my bundle size by putting the package.json to chatgpt and asking it to look for packages to remove and put in devdependencies

mauerbac avatar Sep 12 '24 04:09 mauerbac

If I just want to deploy over the max allowed size, is there a solution now?

phoenixg avatar Sep 25 '24 01:09 phoenixg

Here's a setting that worked for me and removed unnecessary build size by eliminating the step of copying the node_modules. Instead, you can simply reinstall the necessary dependencies directly in the app folder after the build. This helps keep the build smaller and more efficient:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm i
    build:
      commands:
        - env >> .env
        - npm run build
        - mv .env ./.amplify-hosting/compute/default/.env
        - cp package.json ./.amplify-hosting/compute/default/package.json
        - cd .amplify-hosting/compute/default/
        # Reinstall only production dependencies directly in the app folder to reduce size
        - npm install --production
  artifacts:
    baseDirectory: .amplify-hosting
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

camiloux avatar Oct 03 '24 03:10 camiloux

I was able to reduce my bundle size by putting the package.json to chatgpt and asking it to look for packages to remove and put in devdependencies

😂 lol

patrik-simunic-cz avatar Oct 28 '24 15:10 patrik-simunic-cz

im also getting the same error how did you guys solve it??

2025-01-16T05:56:50.313Z [ERROR]: !!! CustomerError: The size of the build output (266387500) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src363436870/src/astro-hybrid/.amplify-hosting/compute/default) and try again

mohd-khan09 avatar Jan 16 '25 06:01 mohd-khan09

Anyone have tips for when you just can't get the size down enough? Is there potentially an alternate way to use Amplify with Astro where it's set up as an Amplify backend?

The funny party is that the @aws-amplify/ui-react library is taking up about 150MB of the 220MB space in node_modules, so by using their official library we're already out over half our budgeted size 😬

lanesawyer avatar Feb 26 '25 17:02 lanesawyer

Another tip for getting the size down (which saved me in the end) - the astro-aws-amplify package itself is >40mb with all its dependencies downloaded, but is only needed during build time as far as I can tell. So you can delete it after building to cut down the build size.

# amplify.yml 
version: 1
frontend:
  phases:
    preBuild:
      commands:
        - "npm ci --cache .npm --omit=dev --prefer-offline"
    build:
      commands:
        - "npm run build"
        - "rm -r node_modules/@swc" # remove other modules that are no longer needed
        - "rm -r node_modules/astro-aws-amplify"
        - "mv node_modules ./.amplify-hosting/compute/default"
  artifacts:
    baseDirectory: .amplify-hosting
    files:
      - "**/*"
  cache:
    paths:
      - ".npm/**/*"

It's kind of annoying to need to manually delete deps like this, but that's currently the only solution AWS provides in their SSR troubleshooting guide.

Zev18 avatar Apr 28 '25 14:04 Zev18