You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js应用部署AWS Amplify遇CustomerError问题求助

解决Next.js部署AWS Amplify时的CustomerError问题

问题场景

构建阶段显示成功,但部署前触发错误:CustomerError: Can't find required-server-files.json in build output directory,完整日志如下:

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...

解决方案

  • 修正Amplify构建配置
    在Amplify控制台的构建设置中,编辑amplify.yml,确保前端构建产物目录指向Next.js的默认输出目录.next,配置示例:

    version: 1
    frontend:
      phases:
        preBuild:
          commands:
            - npm install
        build:
          commands:
            - npm run build
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    
  • 清理缓存重新构建
    在Amplify构建页面选择“重新构建”,勾选“清理缓存”选项,强制生成完整的构建产物,避免缓存导致的文件缺失。

  • 检查Next.js构建命令
    确认项目package.json中的build命令为标准的next build,避免自定义命令跳过生成required-server-files.json:

    {
      "scripts": {
        "build": "next build"
      }
    }
    
  • 确认Next.js版本兼容性
    如果使用Next.js 13+的App Router,确保Amplify已更新至支持该版本的构建环境,避免因框架特性不兼容导致文件生成失败。

内容的提问来源于stack exchange,提问作者Azeem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:37:05