skip to Main Content

I have an issue when I deploy our next js app to AWS amplify the build done but CustomerError occurs that blocks my deployment: here are my logs

2024-01-25T20:11:31.852Z [INFO]: 
2024-01-25T20:11:31.857Z [INFO]: Done in 175.65s.
2024-01-25T20:11:31.874Z [INFO]: # Completed phase: build
2024-01-25T20:11:31.894Z [INFO]: ## Build completed successfully
2024-01-25T20:11:31.896Z [INFO]: # Starting caching...
2024-01-25T20:11:31.909Z [INFO]: # Creating cache artifact...
2024-01-25T20:13:18.327Z [INFO]: # Created cache artifact
2024-01-25T20:13:18.480Z [INFO]: # Uploading cache artifact...
2024-01-25T20:13:28.603Z [INFO]: # Uploaded cache artifact
2024-01-25T20:13:28.703Z [INFO]: # Caching completed
2024-01-25T20:13:28.715Z [ERROR]: !!! CustomerError: Can't find required-server-files.json in build output directory
2024-01-25T20:13:28.716Z [INFO]: # Starting environment caching...
2024-01-25T20:13:28.716Z [INFO]: # Environment caching completed
Terminating logging...

2

Answers


  1. in amplify.yml
    it is because of
    artifacts:
    baseDirectory: "path_is_wrong"

    base directory will start from appRoot that you provided in amplify.yml
    and since it is next base directory’s last folder should be something like "dist/apps/my-app/.next"

    Login or Signup to reply.
  2. If you use Next.js with { output: "export" } config. Add ‘next export" in package.json

    // package.json
    ...
    "scripts": {
      "dev": "next dev",
      "build": "next build && next export",  // Add next export
      "start": "next start",
      "lint": "next lint"
    },
    ...
    

    Amplify performs an automatic build based on the "scripts" in package.json.

    next export is deprecated and replaced with "output": "export" since v13.3. However, However, amplify still decides how to build through "next export".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search