skip to Main Content

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


  1. Although those 2 commands are indicated in the Amplify Docs , this part of the first command:

    ls -al ./.next/standalone/**/*.js
    

    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:

    allfiles=$(ls -1 ./.next/standalone/**/*.js)
    
    
    Login or Signup to reply.
  2. 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

    version: 1
    backend:
      phases:
        build:
          commands:
            - amplifyPush --simple
    frontend:
      phases:
        preBuild:
          commands:
            - npm ci
        build:
          commands:
            - npm run build
            - find ./.next/standalone -type f -name "*.js" | xargs npx esbuild --minify --outdir=.next/standalone --platform=node --target=node16 --format=cjs --allow-overwrite
    
    
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search