I am trying to host a nextjs project in aws amplify. as my app size is more than the amplify limit, I had to use the following command to reduce the size of my app during the build
- allfiles=$(ls -al ./.next/standalone/**/*.js)
- npx esbuild $allfiles --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite
but I got the following error
Invalid build flag: "-rw-r--r--"
it seems there is some permission problem but not sure how to fix it.
nextjs version: 12
Node version: 16
amplify cli version: 10.6.2
I’m new to aws, thank you for your help
2
Answers
Although those 2 commands are indicated in the Amplify Docs , this part of the first command:
returns a list of all the .js files in the directory including their file permissions (e.g. -rw-r–r–). The npx esbuild command expects the input to be file paths, but it’s receiving the file permissions as well.
Try instead:
Made an account specially for this one 🙂
The suggestion to use
ls
is wrong altogether.What happens when you install chart.js?
Instead, you can use the xargs command to pass the list of files from the find command directly to esbuild:
find ./.next/standalone -type f -name "*.js" | xargs npx esbuild --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite"
For example within the amplify build.yaml