aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
448 stars 113 forks source link

CustomerError thrown at the end of build about `sharp-darwin-arm64v8.node` if using `next@13.5.2` #3725

Closed terrymun closed 9 months ago

terrymun commented 9 months ago

Before opening, please confirm:

App Id

d179m7yexeqiqu

AWS Region

eu-west-1

Amplify Hosting feature

Frontend builds

Frontend framework

Next.js

Next.js version

13.5.2

Next.js router

App Router

Describe the bug

When trigger a preview build on AWS Amplify, the build process runs successfully all the way until the end of postBuild, where a CustomerError is thrown complaining about the sharp dependency:

2023-09-23T16:06:56.255Z [INFO]: ## Build completed successfully
2023-09-23T16:06:56.256Z [INFO]: # Starting caching...
2023-09-23T16:06:56.266Z [INFO]: # Creating cache artifact...
2023-09-23T16:08:13.947Z [INFO]: # Created cache artifact
2023-09-23T16:08:14.045Z [INFO]: # Uploading cache artifact...
2023-09-23T16:08:26.515Z [INFO]: # Uploaded cache artifact
2023-09-23T16:08:26.706Z [INFO]: # Caching completed
2023-09-23T16:08:26.713Z [INFO]: # No custom headers found.
2023-09-23T16:08:44.850Z [ERROR]: !!! CustomerError: Required dependency file not found: /codebuild/output/src3916445156/src/kids-frontend/node_modules/sharp/build/Release/sharp-darwin-arm64v8.node
2023-09-23T16:08:44.964Z [INFO]: # Starting environment caching...
2023-09-23T16:08:44.965Z [INFO]: # Environment caching completed
Terminating logging...

Expected behavior

The frontend build should work successfully without throwing an error, as the sharp dependency should've been provided by AWS Amplify as documented: https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplify-support.html#image-optimization

Reproduction steps

  1. Upgrade next.js app to use 13.5.2
  2. Trigger build as usual
  3. Notice that postBuild step fails with the following error message at the very end:

    !!! CustomerError: Required dependency file not found: /codebuild/output/src3916445156/src/kids-frontend/node_modules/sharp/build/Release/sharp-darwin-arm64v8.node

Build Settings

version: '1.0'
frontend:
  phases:
    preBuild:
      commands:
        - nvm use $VERSION_NODE_18
        - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 yarn install --immutable

    build:
      commands:
        - nvm use $VERSION_NODE_18
        - yarn nx run site:build:production

    postBuild:
      commands:
        - if [ "${AWS_BRANCH}" != "main" ] && [ "${QA}" != "True" ]; then yarn ts-node
          ./packages/site-backend/scripts/post-build.ts; fi

  artifacts:
    baseDirectory: dist/packages/site/.next
    files:
      - '**/*'

  cache:
    paths:
      - node_modules/**/*

Log output

``` # Put your logs below this line 2023-09-23T16:06:56.252Z [INFO]: # Completed phase: postBuild 2023-09-23T16:06:56.255Z [INFO]: ## Build completed successfully 2023-09-23T16:06:56.256Z [INFO]: # Starting caching... 2023-09-23T16:06:56.266Z [INFO]: # Creating cache artifact... 2023-09-23T16:08:13.947Z [INFO]: # Created cache artifact 2023-09-23T16:08:14.045Z [INFO]: # Uploading cache artifact... 2023-09-23T16:08:26.515Z [INFO]: # Uploaded cache artifact 2023-09-23T16:08:26.706Z [INFO]: # Caching completed 2023-09-23T16:08:26.713Z [INFO]: # No custom headers found. 2023-09-23T16:08:44.850Z [ERROR]: !!! CustomerError: Required dependency file not found: /codebuild/output/src3916445156/src/kids-frontend/node_modules/sharp/build/Release/sharp-darwin-arm64v8.node 2023-09-23T16:08:44.964Z [INFO]: # Starting environment caching... 2023-09-23T16:08:44.965Z [INFO]: # Environment caching completed Terminating logging... ```

Additional information

Downgrading to next@13.5.1 resolves the issue.

Jay2113 commented 9 months ago

Hi @terrymun 👋 , thanks for raising this!

I was not able to reproduce this error when working with either v13.5.2 or v13.5.3. Are you actively running into this issue with v13.5.2?

Since the issue mitigates with v13.5.1, I wonder if this is some sort of a breaking change from Next.js?

github-actions[bot] commented 9 months ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] commented 9 months ago

This issue has been automatically locked.