Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js 13 Amplify - CustomerError: The size of the build output exceeds the max allowed size of 230686720 bytes #3699

Closed
5 tasks done
foobarnes opened this issue Sep 12, 2023 · 38 comments
Assignees
Labels
archived This issue has been locked. compute investigating

Comments

@foobarnes
Copy link

foobarnes commented Sep 12, 2023

Before opening, please confirm:

  • I have checked to see if my question is addressed in the FAQ.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

App Id

d263pg34gxs8oh

AWS Region

us-east-1

Amplify Hosting feature

Deployments

Frontend framework

Next.js

Next.js version

13.4.13

Next.js router

Pages Router

Describe the bug

CustomerError: The size of the build output (728699832) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output and try again.

Overnight, our deployments have ballooned in size from well under to high above the build size limit (~120,000,000 bytes -> 728,699,832 bytes). Clearly, our application didn't change that drastically between our deployments.

Please do not suggest following these instructions as @Jay2113 did in #3647. Our bundle size should be well under the limit and certainly less than the 728699832 figure given in the error. Plus, those instructions are no longer necessary according to @calavera in #3132.

I am raising this as a separate issue because it just began last night and we do not have enough pages in our app to be anywhere near the ludicrous number provided by the build system.

Expected behavior

Our Next.js 13 app should deploy as usual and be under the bundle size limit for deployment.

Reproduction steps

  1. Merge a change into your GitHub branch to trigger automatic deployment
  2. ...
  3. Profit

Build Settings

version: 1
applications:
  - backend:
      phases:
        build:
          commands:
            - update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.8 11
            - /usr/local/bin/pip3.8 install --user pipenv
            - cd ..
            - amplifyPush --simple
    frontend:
      phases:
        preBuild:
          commands:
            - yarn --ignore-platform
        build:
          commands:
            - yarn build:web --debug
            - env | grep -e NEXT_PUBLIC_ >> .env.production
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - 'node_modules/**/*' # Cache `node_modules` for faster `yarn` or `npm i`
          - '.next/cache/**/*' # Cache Next.js for faster application rebuilds
          - '../node_modules/**/*' # Cache `node_modules` for faster `yarn` or `npm i`
    appRoot: web

Log output

# Put your logs below this line
2023-09-12T19:53:40.396Z [INFO]: # Completed phase: build
2023-09-12T19:53:40.427Z [INFO]: ## Build completed successfully
2023-09-12T19:53:40.430Z [INFO]: # Starting caching...
2023-09-12T19:53:40.442Z [INFO]: # Creating cache artifact...
2023-09-12T19:55:48.348Z [INFO]: # Created cache artifact
2023-09-12T19:55:48.464Z [INFO]: # Uploading cache artifact...
2023-09-12T19:56:05.352Z [INFO]: # Uploaded cache artifact
2023-09-12T19:56:05.585Z [INFO]: # Caching completed
2023-09-12T19:56:05.595Z [INFO]: # No custom headers found.
2023-09-12T19:57:05.969Z [ERROR]: !!! CustomerError: The size of the build output (728706260) exceeds the max allowed size of230686720 bytes. Please reduce the size ofyour build output and try again.
2023-09-12T19:57:06.141Z [INFO]: # Starting environment caching...
2023-09-12T19:57:06.142Z [INFO]: # Uploading environment cache artifact...
2023-09-12T19:57:06.263Z [INFO]: # Uploaded environment cache artifact
2023-09-12T19:57:06.263Z [INFO]: # Environment caching completed

Additional information

  • I am using yarn workspaces with my Next.js app in my ./web directory. (appRoot: web)

Here are some dir sizes:

du -h -d1 public:
332K public/images
360K public

du -h -d1 .next/static:
412K .next/static/css
5.0M .next/static/chunks
12K .next/static/4OD3tkW6Bv-qbps3wPd9U
5.4M .next/static

du -h -d1 .next/server:
3.8M .next/server/chunks
44M .next/server/pages
48M .next/server

@ferdingler
Copy link
Contributor

ferdingler commented Sep 12, 2023

Hi @foobarnes, thanks for the detailed report. We are aware of issues in Next.js 13.4.13+ as they introduced a breaking change in their server handler (vercel/next.js#52492) and we are actively working on a fix. It caught us by surprise as we would normally not expect a breaking change to be introduced on a minor release of next.js. So, apologies for the inconvenience.

Could you try downgrading to next.js 13.4.12 in the meantime as we work on stabilizing newer versions?

@foobarnes
Copy link
Author

Definitely @ferdingler! Thanks so much for getting back so quickly. I'll try that now and update shortly.

@foobarnes
Copy link
Author

@ferdingler It's a no-go. Still got CustomerError: The size of the build output (722400645) exceeds the max allowed size of230686720 bytes. Please reduce the size ofyour build output and try again.

image

@ferdingler
Copy link
Contributor

oh, my bad. I should have explained myself. The Next.js version in the Live package updates may not be a good mechanism to downgrade the version of Next.js. It's better to do it directly in your package.json so that it gets reflected in your package-lock.json file.

npm install --save-exact=true [email protected]

# or with yarn
yarn install --exact [email protected]

and make sure you commit the changes and push both the package.json and package-lock.json or yarn.lock.

@foobarnes
Copy link
Author

foobarnes commented Sep 12, 2023

Sorry, to confirm, I did also pin the specific version of "next" in my package.json.

I also just tried to downgrade @aws-amplify/cli to 12.2.3 with no luck. :/

@foobarnes
Copy link
Author

Do you all have any indication of where it is getting the 722400645 bytes figure?

The only directory/artifact that is that size near deployment time is /amplify.

du -h -d1 .

58M 	./.git
8.0K 	./.github
8.0K 	./.vscode
19M 	./assets
4.0K 	./docs
16K 	./services
7.0M 	./web
705M 	./amplify
788M 	.

./web is my appRoot in amplify.yml for my monorepo.

@foobarnes
Copy link
Author

On my local:

 69M    web/.next/static
 31M    web/.next/server

@foobarnes
Copy link
Author

I've also tried redeploying the last commit that deployed successfully. It failed with the same error.

@victorccccc
Copy link
Contributor

Hi, sorry for the inconvenience, could you do me a favor to try few things:

  1. Try to remove amplify folder at the end of your build?

  2. Add following lines in your next.config.js and build locally and see what is the size of the .next/standalone folder

  output: standalone,
  experimental: {
    outputFileTracingRoot: path.join(__dirname, '../../'),
  },

Thanks

@foobarnes
Copy link
Author

  1. Deploying remove-amplify-folder commit now. Will update shortly.
  2. 177M web/.next/standalone

@foobarnes
Copy link
Author

@victorccccc Removing ./amplify didn't help.

CustomerError: The size of the build output (713809525) exceeds the max allowed size of230686720 bytes. Please reduce the size ofyour build output and try again.

@victorccccc
Copy link
Contributor

Thanks for all the information, we will be continue investigating. Will update here as soon as we find something

@foobarnes
Copy link
Author

An interesting development...

When I changed my frontend > artifacts field to this:

      artifacts:
        baseDirectory: .next/server
        files:
          - '**/*'

My deployment "succeeded", but it deployed my test artifacts instead of any frontend build artifacts.

2023-09-13T00:04:47 [INFO]: Starting Deployment
2023-09-13T00:04:47 [INFO]: Start deploying test artifact
2023-09-13T00:04:47 [INFO]: Deploying videos/1-auth/signin.cy.js.mp4
2023-09-13T00:04:47 [INFO]: Deploying videos/3-creators/create.cy.js.mp4
2023-09-13T00:04:47 [INFO]: Deploying videos/4-analytics-page/additional-metrics.cy.js.mp4
2023-09-13T00:04:47 [INFO]: Deploying videos/5-s3-images/save-delete-from-s3.cy.js.mp4
2023-09-13T00:04:48 [INFO]: Finish deploying test artifact
2023-09-13T00:04:48 [INFO]: Updating Edge config

Returning frontend > artifacts back to its original form returned me to my usual error.

@foobarnes
Copy link
Author

@victorccccc When I build standalone in the Amplify build container, I see a standalone size closer to that 700MB we're seeing in the error:

...
8.5M	.next/standalone/rootnote/node_modules/@esbuild/linux-ppc64/bin
8.6M	.next/standalone/rootnote/node_modules/@esbuild/linux-ppc64
8.5M	.next/standalone/rootnote/node_modules/@esbuild/linux-riscv64/bin
8.5M	.next/standalone/rootnote/node_modules/@esbuild/linux-riscv64
9.4M	.next/standalone/rootnote/node_modules/@esbuild/linux-s390x/bin
9.4M	.next/standalone/rootnote/node_modules/@esbuild/linux-s390x
9.0M	.next/standalone/rootnote/node_modules/@esbuild/linux-x64/bin
9.0M	.next/standalone/rootnote/node_modules/@esbuild/linux-x64
8.9M	.next/standalone/rootnote/node_modules/@esbuild/netbsd-x64/bin
8.9M	.next/standalone/rootnote/node_modules/@esbuild/netbsd-x64
9.0M	.next/standalone/rootnote/node_modules/@esbuild/openbsd-x64/bin
9.0M	.next/standalone/rootnote/node_modules/@esbuild/openbsd-x64
8.9M	.next/standalone/rootnote/node_modules/@esbuild/sunos-x64/bin
9.0M	.next/standalone/rootnote/node_modules/@esbuild/sunos-x64
8.4M	.next/standalone/rootnote/node_modules/@esbuild/win32-arm64
8.8M	.next/standalone/rootnote/node_modules/@esbuild/win32-ia32
9.2M	.next/standalone/rootnote/node_modules/@esbuild/win32-x64
198M	.next/standalone/rootnote/node_modules/@esbuild
666M	.next/standalone/rootnote/node_modules
708M	.next/standalone/rootnote
708M	.next/standalone

@Jay2113
Copy link
Contributor

Jay2113 commented Sep 13, 2023

@foobarnes thanks for sharing the additional information, this is very helpful.

We would like to schedule a call with you to discuss about this further. Can you please reach out via a DM on our community discord server? My username is Jay Raval.

Thanks!

@foobarnes
Copy link
Author

Some notable package size differences between locally-generated and amplify-generated .next/standalone:

Package	|	Local 	| 	Amplify
@swc	|	36K 	| 	375M
@esbuild|	--- 	| 	198M
next	|	796K 	| 	20M

@foobarnes
Copy link
Author

For posterity:
We just tried removing two files that Amplify uses to run its file trace for files to bundle into the deployment:
.next/next-server.js.nft.json and .next/next-minimal-server.js.nft.json

It didn't work for me, but may for future generations to come.

@foobarnes
Copy link
Author

We identified that all of the SWC binaries (listed as optionalDependencies on the next package) were being downloaded and bundled when they shouldn't have.

An unideal workaround that unblocked my deployments:
swcMinify: false in my next.config.js
yarn install --ignore-optional in my amplify.yml

@Tomekmularczyk
Copy link

Hey guys we are experiencing the same issue after trying to integrate Sentry. I initially thought it's the problem with Sentry but Maintainers of Sentry suggest I should ask here.

link to the discussion

@Tomekmularczyk
Copy link

any update? this is blocker for us

@danoshi
Copy link

danoshi commented Oct 11, 2023

I have the same issue, is there any update on this?

@meryemben92
Copy link

Hello, I have the same issue, is there any news ?

@christowiz
Copy link

I've also been unable to successfully deploy a Next.js 13 app for some time now.

@kaito-hao
Copy link

We've hit this issue too, please share some update if any. Thank you.

@frattaro
Copy link

Has anyone tried skipping to next 14/amazon linux 2023 now that this is done #3773 (comment) ?

I would try but one of our dependencies needs to fix it's peerdeps

@elitar
Copy link

elitar commented Nov 20, 2023

Has anyone tried skipping to next 14/amazon linux 2023 now that this is done #3773 (comment) ?

I would try but one of our dependencies needs to fix it's peerdeps

I've tried it - didn't work for me.
Still waiting for a solution here.

@bstenm
Copy link

bstenm commented Nov 25, 2023

Just in case that helps, it seems that for me for some reason the error only happens when I use pnpm instead of npm or yarn to install the dependencies.

@Benhatsdrauf
Copy link

Having the same problem with Next 14.
Has somebody found any workaround or solution to get this fixed ?

@jitendra-koodo
Copy link

+1

@vishalobrizum
Copy link

Running into this error. Why can't you increase the limit of 200MB

@vishalobrizum
Copy link

vishalobrizum commented Dec 11, 2023

Hey guys we are experiencing the same issue after trying to integrate Sentry. I initially thought it's the problem with Sentry but Maintainers of Sentry suggest I should ask here.

link to the discussion

We are having the exact same issue! Why can't you increase the hard limit of 200MB. I am sure a company whose value is 1.5 trillion USD, I am sure its not that difficult

@Benhatsdrauf
Copy link

I think this is only a workaround for now but this did the trick for us.
Maybe it will help some of you as well :D

image

@kaito-hao
Copy link

I think this is only a workaround for now but this did the trick for us. Maybe it will help some of you as well :D

image

Hi, could you please add a little more explanation on what was the trick and how/why it works?

I added your backend commands to my build script, it created a new Backend environment, however all my others are Hosting environment (managed by CDK). I understand that I may use a different deploy method than yours, but knowing a little more details might help me do some tricks as well :D

@Benhatsdrauf
Copy link

Hi, this is the whole amplify.yml file in the build settings from our hosting.

The command i added removes the cache from the build because i think some parts of the next code get generated new on every build which is than cached and that adds up over time 🤔 .

I hope this helps, i am new to aws and amplify myself so im sorry that i cant give you a better description than this :(

image

@vishalobrizum
Copy link

Hi, this is the whole amplify.yml file in the build settings from our hosting.

The command i added removes the cache from the build because i think some parts of the next code get generated new on every build which is than cached and that adds up over time 🤔 .

I hope this helps, i am new to aws and amplify myself so im sorry that i cant give you a better description than this :(

image

Tried adding the backend commands and redeploying, still running into the same issue

@victorccccc
Copy link
Contributor

Hi 👋, we recently made the improvement and resolved this issue, please rebuild your application. Feel free to open the new issue if it persists. Thanks

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Copy link

This issue has been automatically locked.

@github-actions github-actions bot added the archived This issue has been locked. label Dec 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked. compute investigating
Projects
None yet
Development

No branches or pull requests