Closed ShiftySlothe closed 1 year ago
Hi @ShiftySlothe 👋🏽 Please try running a build locally to ensure that the standalone
directory is being created:
export NEXT_PRIVATE_STANDALONE=true
npm run build # or yarn build
Also please ensure that you are using Next.js version 11 13 or 12.
Hey @hloriana thanks for the response.
https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplify-support.html makes it clear you support NextJS 13. Is this not the case?
I can also confirm the standalone repo is working locally.
EDIT:
I note that in the screenshot taken from the article about hosting Next13 "framework" is set.
However on my build settings I do not see this option.
EDIT 2: I've now created a new branch with just the start template you use on the article I linked above and it initially failed, having ran aws amplify update-branch
setting --framework 'Next.js - SSR
, it builds. I'm working through including my project files in the hope of identifying what's causing the error.
EDIT 3: I've successfully built the majority of the site now using Next13, I had to add pages incrementally, build and finally it would allow me to build all the pages! However, I now get this issue:
[ERROR]: !!! CustomerError: The size of the build output (483856351) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src002007246/src/lawhive.co.uk/.next/standalone) and try again.
Is it possible to increase this figure?
I have met this issue too.
2022-11-23T03:21:23.355Z [ERROR]: !!! CustomerError: The size of the build output (425981801) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src013718944/src/alphaswift/.next/standalone) and try again.
Hi, unfortunately there is a hard limit of 200MB for the bundle. Our current recommendation for now is to try to reduce the size by minimizing your files.
Is there a plan to allow increases to that limit in the future and do you have an idea of timelines? We're minimising already however our site has a large number of pages and I doubt we can shave 50% off the bundle size.
this is a problem that we're looking into, but we don't have a timeline at the moment. Something that would help us is if you could add here the output of running these three commands:
du -h -d1 public
du -h -d1 .next/static
du -h -d1 .next/server
I ran into this same CustomerError: The size of the build output exceeds the max allowed size
. Fortunately for this project I was able to minimize the contents of the public folder to sneak just under this limit. The workaround for me going forward with large asset-heavy next.js projects might be to host all my public assets on cloudfront/s3 and use the assetPrefix
option in next.config.js to request static assets from cloudfront instead of the nextjs server.
This would be very in-line with next.js's edge-first philosophy. I'd be interested to see if the Amplify team could implement that kind of thing as part of the build process.
Hi,
We have the same issue here:
!!! CustomerError: The size of the build output (676020993) exceeds the max allowed size of 230686720 bytes.
It worked before we upgraded to Web Compute with the same project.
I solved it temporarily by excluding paths in getStaticPaths and generating the pages on demand for some paths.
But that's not an ideal solution. The build output is limited to 220MB, meaning it's possible to statically build about 1 800 pages during the build process if each page is 125KB.
Hey,
Just started to look to use AWS Amplify for my NextJS13 app. I've also ran into the build size issue. My NextJS is using SSR for all pages.
Errror !!! CustomerError: The size of the build output (238747580) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src445488485/src/web-ui/.next/standalone) and try again.
I've attempted what was suggested by the docs and added the following to my build step in the .yml file
- allfiles=$(ls -al ./.next/standalone/**/*.js)
- npx esbuild $allfiles --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite
However this provides another error
# Executing command: allfiles=lrwxrwxrwx 1 root root 42 Dec 4 01:59 ./.next/standalone/node_modules/tippy.js -> .pnpm/tippy.js@6.3.7/node_modules/tippy.js
# Executing command: npx esbuild lrwxrwxrwx 1 root root 42 Dec 4 01:59 ./.next/standalone/node_modules/tippy.js -> .pnpm/tippy.js@6.3.7/node_modules/tippy.js --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite
✘ [ERROR] Invalid build flag: "->" 1 error
Not sure if this is related to the fact I'm using pnpm
to install and manage my dependencies however I've checked esbuild
support of pnpm and they appear to support symlinks https://github.com/evanw/esbuild/issues/310.
I've searched around for this error but have been unable to find anything.
Also here is an output of the three commands
╰─ du -h -d1 public
13M public/static
13M public
╰─ du -h -d1 .next/static
72K .next/static/css
11M .next/static/chunks
20K .next/static/ilatlR2YlvJYNcYiWmMmj
11M .next/static
╰─ du -h -d1 .next/server
6.6M .next/server/chunks
22M .next/server/pages
644K .next/server/src
30M .next/server
Will see if there's anything I can do to reduce it but any feedback or direction would be greatly appreciated.
Hey,
Just started to look to use AWS Amplify for my NextJS13 app. I've also ran into the build size issue. My NextJS is using SSR for all pages.
Errror
!!! CustomerError: The size of the build output (238747580) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src445488485/src/web-ui/.next/standalone) and try again.
I've attempted what was suggested by the docs and added the following to my build step in the .yml file
- allfiles=$(ls -al ./.next/standalone/**/*.js) - npx esbuild $allfiles --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite
However this provides another error
# Executing command: allfiles=lrwxrwxrwx 1 root root 42 Dec 4 01:59 ./.next/standalone/node_modules/tippy.js -> .pnpm/tippy.js@6.3.7/node_modules/tippy.js # Executing command: npx esbuild lrwxrwxrwx 1 root root 42 Dec 4 01:59 ./.next/standalone/node_modules/tippy.js -> .pnpm/tippy.js@6.3.7/node_modules/tippy.js --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite ✘ [ERROR] Invalid build flag: "->" 1 error
Not sure if this is related to the fact I'm using
pnpm
to install and manage my dependencies however I've checkedesbuild
support of pnpm and they appear to support symlinks evanw/esbuild#310.I've searched around for this error but have been unable to find anything.
Also here is an output of the three commands
╰─ du -h -d1 public 13M public/static 13M public ╰─ du -h -d1 .next/static 72K .next/static/css 11M .next/static/chunks 20K .next/static/ilatlR2YlvJYNcYiWmMmj 11M .next/static ╰─ du -h -d1 .next/server 6.6M .next/server/chunks 22M .next/server/pages 644K .next/server/src 30M .next/server
Will see if there's anything I can do to reduce it but any feedback or direction would be greatly appreciated.
It's over a month later, but I found that:
ls -al
did not like the globstar (**) and included directories and file path symbols such as the symlinks you mentioned.If you create a minify.sh bash script and add it to your build steps in amplify.yml, this worked for reducing my bundle size:
#!/bin/bash
cd .next/standalone/node_modules
for d in $(find . -maxdepth 1 -type d); do
npx --yes esbuild $(find $d -type f -name '*.js') --minify --outdir=$d --platform=node --target=node16 --format=cjs --allow-overwrite
done
cd -
Unfortunately, even after meeting the size requirements, WEB_COMPUTE is currently having a deployment bundling issue that is causing deployments to fail silently #3213.
It's over a month later, but I found that:
- The
ls -al
did not like the globstar (**) and included directories and file path symbols such as the symlinks you mentioned.- There were too many files for me to run in a single pass of esbuild on the default Amplify build container.
If you create a minify.sh bash script and add it to your build steps in amplify.yml, this worked for reducing my bundle size:
#!/bin/bash cd .next/standalone/node_modules for d in $(find . -maxdepth 1 -type d); do npx --yes esbuild $(find $d -type f -name '*.js') --minify --outdir=$d --platform=node --target=node16 --format=cjs --allow-overwrite done cd -
Unfortunately, even after meeting the size requirements, WEB_COMPUTE is currently having a deployment bundling issue that is causing deployments to fail silently #3213.
I've run this script and I can't seem to get my output size down any further. I've also tried running esbuild on .next/standalone/.next
but that didn't help very much.
cd .next/standalone/node_modules
for d in $(find . -maxdepth 1 -type d); do
npx --yes esbuild $(find $d -type f -name '*.js') --minify --outdir=$d --platform=node --target=node16 --format=cjs --allow-overwrite
done
cd -
cd .next/standalone/.next
for d in $(find . -maxdepth 1 -type d); do
npx --yes esbuild $(find $d -type f -name '*.js') --minify --outdir=$d --platform=node --target=node16 --format=cjs --allow-overwrite
done
cd -
Running esbuild helped a bit as I've gotten the bundle size from 240572524
to 234879691
but there still remains ~5 MB.
CustomerError: The size of the build output (234879691) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src129382/src/my-project/.next/standalone) and try again
Any help reducing this bundle size would be greatly appreciated.
@calavera
this is a problem that we're looking into, but we don't have a timeline at the moment. Something that would help us is if you could add here the output of running these three commands:
$ du -h -d1 public
604K public/posts
48K public/images
3.1M public
$ du -h -d1 .next/static
34M .next/static/chunks
24K .next/static/ICQyTuaWXQ1OObGk8yzsN
152K .next/static/css
34M .next/static
$ du -h -d1 .next/server
1.7M .next/server/chunks
21M .next/server/pages
23M .next/server
Running the minify script seemed to do something ... but the output from du
didn't change one bit so I'm not sure if anything was achieved :(
Updating to add that when getting Amplify to build my application, the minify script reduced the build output from 463721822 to 450400919 ... so that didn't really help much :(
FYI standalone dir errors can appear also when using a monorepo - https://github.com/aws-amplify/amplify-hosting/issues/3179
Noting here that I am also a victim of the Amplify build limit for a production application we're looking to upgrade to Next.js 13 🥲
!!! CustomerError: The size of the build output (344395275) exceeds the max allowed size of 230686720 bytes. Please reduce the size of your build output (/codebuild/output/src888343114/src/alcohol-101-plus/services/app/.next/standalone) and try again
And this is after using ESBuild following this StackOverflow post
Has anyone found a solution to the original problem. I also am getting an error for not having a standalone directory.
I get the same issue, and it's a road blocker for me.
du -h -d1 .next/server
I'm stuck too, and would need to find an alternative hosting provider due to this limitation.
I was having issues as well similar to those above however we couldn't wait and really wanted to reap the benefits of serverless, edge and nextjs 13. Luckily we found another solution that also deploys to AWS services (lambda, apigateway, etc) and has been working really well in our tests so far: https://sst.dev/. Would recommend for those that want to still utilize AWS and need a working solution now.
I solved the error "CustomerError: Standalone directory not found" doing the following:
Step 1: Update Next.js to the latest version.
Step 2: Add the standalone setting to the next.config.js file.
const nextConfig = {
reactStrictMode: true,
output: 'standalone',
images: {
unoptimized: true,
}
}
module.exports = nextConfig
Step 3: Update the build script in the package.json file to include the next export command, which generates the static files for the app:
"scripts": {
"dev": "next dev",
"build": "next build && next export",
"start": "next start",
"lint": "next lint"
}
Step 4: Change the output directory to out. This is where the generated static files will be stored. Here's an example of what your deployment configuration might look like:
version: 1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: out
files:
- '**/*'
cache:
paths:
- node_modules/**
I hope it works for you.
I still having this issue
NextJS 13 error still occurs.
amplify.yml has very straightforward configuration
version: 1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
du -s .next/standalone/
159720 .next/standalone/
Standalone folder approximately 80 mbs
As you see in the screenshot. On Amplify build phase it still gives error for exceeding the build output size.
@sawakaga have you managed to find a solution? Seeing the same on Amplify today. Running du -sh .next/standalone
locally outputs 109MB.
same problem here
@rafaelvicio if you use pnpm
, can you try adding pnpm config set node-linker hoisted
before pnpm install
? Seems like this solved the problem for us.
@kachkaev Thank you.
@rafaelvicio if you use
pnpm
, can you try addingpnpm config set node-linker hoisted
beforepnpm install
? Seems like this solved the problem for us.
This worked for me by placing these commands into an .npmrc
file. Sub-optimal but it unblocked the build.
!!! CustomerError: The size of the build output (xxx) exceeds the max allowed size of xxx bytes.
Error
@sawakaga have you managed to find a solution? Seeing the same on Amplify today. Running
du -sh .next/standalone
locally outputs 109MB.
Problem still occurs unfortunately. Currently we dont host application on amplify
Just wanted to update you all that I successfully migrated our company's Next.js 11 project to Next.js 13. However, I encountered an issue with the bundle size, which was over 900MB. I reached out to AWS support, and after some discussions and various attempts to fix it, we concluded that we need to wait for the issue to be resolved as they are currently working on it.
In case you're interested, here's the documentation I found regarding a potential solution using the command placement in the amplify.yml file after the build step: Amplify Troubleshooting SSR Deployment
facing same issue
Hey everyone 👋
We just released some changes to improve how we bundle Next.js apps. These changes don't need the standalone directory anymore. That should help eliminate the problem of reaching the 200MB bundle limit. These changes require a new deploy in your application to take effect. The expected outcome is that your app bundles should be smaller, and not bump into the size limit.
If you have comments or questions don't hesitate to reach us via AWS support.
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.
This issue has been automatically locked.
Before opening, please confirm:
App Id
d3lq4oet4t4ooj
AWS Region
eu-west-1
Amplify Hosting feature
Frontend builds
Describe the bug
Standalone directory not found, please enable output standalone on your next.config.js file or set NEXT_PRIVATE_STANDALONE=true.
Output is standalone in next.config.js AND set to true as an ENV variable.
It appears that the build is finishing early for some reason.
On a single build, it could find the standalone output, but deemed the output to be too large.
Expected behavior
Build runs sucessfully.
Reproduction steps
Run build, await standalone directory not to be found.
Build Settings
Log output
Additional information
No response