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

Next.js 14部署AWS Amplify遇SIGKILL错误求助

解决Next.js 14部署AWS Amplify时的SIGKILL构建失败问题

我把Next.js 14应用通过GitHub部署到AWS Amplify时,碰到了「Command failed with signal "SIGKILL"」错误。本地构建完全正常,但Amplify上构建失败,相关日志和yaml配置如下:

构建错误日志

2024-02-14T11:38:36.569Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2024-02-14T11:38:36.569Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2024-02-14T11:38:36.670Z [INFO]: ▲ Next.js 14.1.0
2024-02-14T11:38:36.671Z [INFO]: - Environments: .env.production
                                 - Experiments (use at your own risk):
                                 · missingSuspenseWithCSRBailout
2024-02-14T11:38:36.749Z [INFO]: Creating an optimized production build ...
2024-02-14T11:41:17.953Z [WARNING]: error Command failed with signal "SIGKILL".
2024-02-14T11:41:18.040Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2024-02-14T11:41:18.151Z [ERROR]: !!! Build failed
2024-02-14T11:41:18.151Z [INFO]: Please read more about Amplify Hosting's support for SSR frameworks to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-ssr-framework-support.html. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html
2024-02-14T11:41:18.152Z [ERROR]: !!! Error: Command failed with exit code 1
2024-02-14T11:41:18.152Z [INFO]: # Starting environment caching...
2024-02-14T11:41:18.152Z [INFO]: # Environment caching completed
Terminating logging...

原Amplify构建配置(yaml)

version: 1.0
frontend:
  phases:
    preBuild:
      commands:
        - nvm use 18
        - yarn install
    build:
      commands:
        - env | grep -e NEXT_PUBLIC_ >> .env.production
        - yarn run build
  artifacts:
    baseDirectory: .next/
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

解决办法

1. 解决内存不足问题(最常见原因)

SIGKILL通常是构建进程占用内存超过Amplify环境限制被系统杀死,给Node.js分配更多内存:
修改构建命令,在yarn run build前添加内存参数:

NODE_OPTIONS="--max-old-space-size=4096" yarn run build

如果4GB不够,可尝试调整为5120(5GB),但不要超过Amplify构建环境的上限。

2. 优化环境变量配置

避免在构建阶段写入.env文件,直接在Amplify控制台的「环境变量」页面添加所有NEXT_PUBLIC_开头的变量,然后删除构建阶段的env | grep -e NEXT_PUBLIC_ >> .env.production命令。

3. 固定Node.js版本

确保Amplify使用的Node版本和本地一致,比如指定具体版本:

nvm use 18.19.0

4. 清理缓存重试

临时注释掉yaml中的cache部分,重新触发构建,排除缓存异常问题,构建成功后再恢复缓存配置。

修改后的示例配置

version: 1.0
frontend:
  phases:
    preBuild:
      commands:
        - nvm use 18.19.0
        - yarn install
    build:
      commands:
        - NODE_OPTIONS="--max-old-space-size=4096" yarn run build
  artifacts:
    baseDirectory: .next/
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 04:53:14