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

AWS Amplify部署失败求助:前端预构建npm依赖冲突

AWS Amplify部署失败:前端预构建npm ci依赖冲突

问题描述

更新AWS Amplify应用时,后端构建成功,但前端预构建阶段npm ci执行失败,本地运行正常,重新部署之前成功的版本也失败。核心错误为aws-appsync依赖的@react-native-community/async-storage与项目React 17.0.2版本冲突,同时存在旧版Material UI的peer依赖警告。

完整构建日志:

2022-11-17T22:49:16.082Z [INFO]: ## Starting Frontend Build
                                 # Starting phase: preBuild
2022-11-17T22:49:16.082Z [INFO]: # Executing command: npm ci
2022-11-17T22:49:20.209Z [WARNING]: npm
2022-11-17T22:49:20.211Z [WARNING]: WARN ERESOLVE overriding peer dependency
                                    npm WARN While resolving: @material-ui/core@3.9.3
                                    npm WARN Found: react@"^17.0.2"
                                    npm WARN node_modules/react
                                    npm WARN   react@"^17.0.2" from the root project
                                    npm WARN   57 more (@coreui/icons-react, @coreui/react, ...)
                                    npm WARN
                                    npm WARN Could not resolve dependency:
                                    npm WARN peer react@"^16.3.0" from @material-ui/core@3.9.3
                                    npm WARN node_modules/@material-ui/core
                                    npm WARN   peer @material-ui/core@"^3.2.0" from material-ui-pickers@2.2.4
                                    npm WARN   node_modules/material-ui-pickers
                                    npm WARN   1 more (mdbreact)
                                    npm WARN
                                    npm WARN Conflicting peer dependency: react@16.14.0
                                    npm WARN node_modules/react
                                    npm WARN   peer react@"^16.3.0" from @material-ui/core@3.9.3
                                    npm WARN   node_modules/@material-ui/core
                                    npm WARN     peer @material-ui/core@"^3.2.0" from material-ui-pickers@2.2.4
                                    npm WARN     node_modules/material-ui-pickers
                                    npm WARN     1 more (mdbreact)
2022-11-17T22:49:20.218Z [WARNING]: npm WARN
2022-11-17T22:49:20.218Z [WARNING]: ERESOLVE overriding peer dependency
                                    npm WARN While resolving: @material-ui/core@3.9.3
                                    npm WARN Found: react-dom@"^17.0.2"
                                    npm WARN node_modules/react-dom
                                    npm WARN   react-dom@"^17.0.2" from the root project
                                    npm WARN   21 more (@coreui/react, @hookform/error-message, ...)
                                    npm WARN
                                    npm WARN Could not resolve dependency:
                                    npm WARN peer react-dom@"^16.3.0" from @material-ui/core@3.9.3
                                    npm WARN node_modules/@material-ui/core
                                    npm WARN   peer @material-ui/core@"^3.2.0" from material-ui-pickers@2.2.4
                                    npm WARN   node_modules/material-ui-pickers
                                    npm WARN   1 more (mdbreact)
                                    npm WARN
                                    npm WARN Conflicting peer dependency: react-dom@16.14.0
                                    npm WARN node_modules/react-dom
                                    npm WARN   peer react-dom@"^16.3.0" from @material-ui/core@3.9.3
                                    npm WARN   node_modules/@material-ui/core
                                    npm WARN     peer @material-ui/core@"^3.2.0" from material-ui-pickers@2.2.4
                                    npm WARN     node_modules/material-ui-pickers
                                    npm WARN     1 more (mdbreact)
2022-11-17T22:49:20.224Z [WARNING]: npm WARN ERESOLVE overriding peer dependency
2022-11-17T22:49:20.225Z [WARNING]: npm WARN While resolving: @material-ui/system@3.0.0-alpha.2
                                    npm WARN Found: react@"^17.0.2"
                                    npm WARN node_modules/react
                                    npm WARN   react@"^17.0.2" from the root project
                                    npm WARN   57 more (@coreui/icons-react, @coreui/react, ...)
                                    npm WARN
                                    npm WARN Could not resolve dependency:
                                    npm WARN peer react@"^16.3.0" from @material-ui/system@3.0.0-alpha.2
                                    npm WARN node_modules/@material-ui/system
                                    npm WARN   @material-ui/system@"^3.0.0-alpha.0" from @material-ui/core@3.9.3
                                    npm WARN   node_modules/@material-ui/core
                                    npm WARN
                                    npm WARN Conflicting peer dependency: react@16.14.0
                                    npm WARN node_modules/react
                                    npm WARN   peer react@"^16.3.0" from @material-ui/system@3.0.0-alpha.2
                                    npm WARN   node_modules/@material-ui/system
2022-11-17T22:49:20.225Z [WARNING]: npm WARN     @material-ui/system@"^3.0.0-alpha.0" from @material-ui/core@3.9.3
                                    npm WARN     node_modules/@material-ui/core
2022-11-17T22:49:20.229Z [WARNING]: npm WARN ERESOLVE overriding peer dependency
                                    npm WARN While resolving: @material-ui/system@3.0.0-alpha.2
                                    npm WARN Found: react-dom@"^17.0.2"
2022-11-17T22:49:20.229Z [WARNING]: npm WARN node_modules/react-dom
                                    npm WARN   react-dom@"^17.0.2" from the root project
                                    npm WARN   21 more (@coreui/react, @hookform/error-message, ...)
                                    npm WARN
                                    npm WARN Could not resolve dependency:
                                    npm WARN peer react-dom@"^16.3.0" from @material-ui/system@3.0.0-alpha.2
                                    npm WARN node_modules/@material-ui/system
                                    npm WARN   @material-ui/system@"^3.0.0-alpha.0" from @material-ui/core@3.9.3
                                    npm WARN   node_modules/@material-ui/core
                                    npm WARN
                                    npm WARN Conflicting peer dependency: react-dom@16.14.0
                                    npm WARN node_modules/react-dom
                                    npm WARN   peer react-dom@"^16.3.0" from @material-ui/system@3.0.0-alpha.2
                                    npm WARN   node_modules/@material-ui/system
                                    npm WARN     @material-ui/system@"^3.0.0-alpha.0" from @material-ui/core@3.9.3
                                    npm
2022-11-17T22:49:20.229Z [WARNING]: WARN     node_modules/@material-ui/core
2022-11-17T22:49:20.235Z [WARNING]: npm WARN
2022-11-17T22:49:20.235Z [WARNING]: ERESOLVE overriding peer dependency
                                    npm WARN While resolving: @material-ui/utils@3.0.0-alpha.3
                                    npm WARN Found: react@"^17.0.2"
                                    npm WARN node_modules/react
                                    npm WARN   react@"^17.0.2" from the root project
                                    npm WARN   57 more (@coreui/icons-react, @coreui/react, ...)
                                    npm WARN
                                    npm WARN Could not resolve dependency:
                                    npm WARN peer react@"^16.3.0" from @material-ui/utils@3.0.0-alpha.3
                                    npm WARN node_modules/@material-ui/utils
                                    npm WARN   @material-ui/utils@"^3.0.0-alpha.2" from @material-ui/core@3.9.3
                                    npm WARN   node_modules/@material-ui/core
                                    npm
2022-11-17T22:49:20.235Z [WARNING]: WARN
                                    npm WARN Conflicting peer dependency: react@16.14.0
                                    npm WARN node_modules/react
                                    npm WARN   peer react@"^16.3.0" from @material-ui/utils@3.0.0-alpha.3
                                    npm WARN   node_modules/@material-ui/utils
                                    npm WARN     @material-ui/utils@"^3.0.0-alpha.2" from @material-ui/core@3.9.3
                                    npm WARN     node_modules/@material-ui/core
2022-11-17T22:49:20.240Z [WARNING]: npm WARN ERESOLVE
2022-11-17T22:49:20.240Z [WARNING]: overriding peer dependency
                                    npm WARN While resolving: @material-ui/utils@3.0.0-alpha.3
                                    npm WARN Found: react-dom@"^17.0.2"
                                    npm WARN node_modules/react-dom
                                    npm WARN   react-dom@"^17.0.2" from the root project
                                    npm WARN   21 more (@coreui/react, @hookform/error-message, ...)
                                    npm WARN
                                    npm WARN Could not resolve dependency:
                                    npm WARN peer react-dom@"^16.3.0" from @material-ui/utils@3.0.0-alpha.3
                                    npm WARN node_modules/@material-ui/utils
                                    npm WARN   @material-ui/utils@"^3.0.0-alpha.2" from @material-ui/core@3.9.3
                                    npm WARN   node_modules/@material-ui/core
                                    npm WARN
                                    npm WARN Conflicting peer dependency: react-dom@16.14.0
                                    npm WARN node_modules/react-dom
                                    npm WARN   peer react-dom@"^16.3.0" from @material-ui/utils@3.0.0-alpha.3
                                    npm WARN   node_modules/@material-ui/utils
                                    npm WARN     @material-ui/utils@"^3.0.0-alpha.2" from @material-ui/core@3.9.3
                                    npm
2022-11-17T22:49:20.240Z [WARNING]: WARN     node_modules/@material-ui/core
2022-11-17T22:49:28.722Z [WARNING]: npm ERR! code ERESOLVE
2022-11-17T22:49:28.725Z [WARNING]: npm ERR!
2022-11-17T22:49:28.725Z [WARNING]: ERESOLVE could not resolve
                                    npm ERR!
                                    npm ERR! While resolving: aws-appsync@4.0.5
                                    npm ERR! Found: react@"^17.0.2"
                                    npm ERR! node_modules/react
                                    npm ERR!   react@"^17.0.2" from the root project
                                    npm ERR!   peer react@"^17.0.1" from @coreui/icons-react@1.1.0
                                    npm ERR!   node_modules/@coreui/icons-react
                                    npm ERR!     @coreui/icons-react@"^1.1.0" from the root project
                                    npm ERR!   56 more (@coreui/react, @coreui/react-chartjs, @emotion/react, ...)
                                    npm ERR!
2022-11-17T22:49:28.725Z [WARNING]: 
                                    npm ERR! Could not resolve dependency:
                                    npm ERR! peer @react-native-community/async-storage@"^1.11.0" from aws-appsync@4.0.5
                                    npm ERR! node_modules/aws-appsync
                                    npm ERR!   aws-appsync@"^4.0.3" from the root project
                                    npm ERR!   peer aws-appsync@"3.x.x || 4.x.x" from aws-appsync-react@4.0.5
                                    npm ERR!   node_modules/aws-appsync-react
                                    npm ERR!     aws-appsync-react@"^4.0.3" from the root project
                                    npm ERR!
                                    npm ERR! Conflicting peer dependency: react@16.14.0
                                    npm ERR! node_modules/react
                                    npm ERR!   peer react@"^16.8" from @react-native-community/async-storage@1.12.1
                                    npm ERR!   node_modules/@react-native-community/async-storage
                                    npm ERR!     peer @react-native-community/async-storage@"^1.11.0" from aws-appsync@4.0.5
                                    npm ERR!     node_modules/aws-appsync
                                    npm ERR!       aws-appsync@"^4.0.3" from the root project
                                    npm ERR!       1 more (aws-appsync-react)
                                    npm ERR!
                                    npm ERR! Fix the upstream dependency conflict, or retry
                                    npm ERR! this command with --force, or --legacy-peer-deps
                                    npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
                                    npm ERR!
                                    npm ERR! See /root/.npm/eresolve-report.txt for a full report.
2022-11-17T22:49:28.726Z [WARNING]: npm
2022-11-17T22:49:28.726Z [WARNING]: ERR! A complete log of this run can be found in:
                                    npm ERR!     /root/.npm/_logs/2022-11-17T22_49_16_301Z-debug-0.log
2022-11-17T22:49:28.737Z [ERROR]: !!! Build failed
2022-11-17T22:49:28.737Z [ERROR]: !!! Non-Zero Exit Code detected
2022-11-17T22:49:28.737Z [INFO]: # Starting environment caching...
2022-11-17T22:49:28.737Z [INFO]: # Uploading environment cache artifact...
2022-11-17T22:49:28.807Z [INFO]: # Uploaded environment cache artifact
2022-11-17T22:49:28.807Z [INFO]: # Environment caching completed
Terminating logging...

已尝试的操作:

  • 重新部署之前成功的构建版本
  • 修改amplify.yaml在npm ci后添加--legacy-peer-deps
  • 手动更新日志中提及的依赖库

解决方案

1. 解决aws-appsync的核心依赖冲突(优先推荐)

aws-appsync@4.x版本引入了React Native的async-storage依赖,而该包仅支持React 16,与项目的React 17冲突。可以降级到3.x版本:

  • 执行命令:
    npm install aws-appsync@3.1.12 aws-appsync-react@3.1.12 --save-exact
    
  • 删除本地package-lock.json和node_modules,执行npm ci验证本地安装正常
  • 提交修改后的配置文件,重新部署Amplify

2. 确保amplify.yaml的--legacy-peer-deps配置正确

如果坚持使用4.x版本,需确保构建命令正确传递参数:

  • 编辑项目根目录的amplify.yaml,找到preBuild阶段,修改为:
    version: 1
    frontend:
      phases:
        preBuild:
          commands:
            - npm ci --legacy-peer-deps
        build:
          commands:
            - npm run build
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    
  • 提交修改后的yaml文件,重新部署

3. 替换React Native async-storage为Web兼容包

使用Web版的async-storage替代React Native版本,通过npm overrides强制aws-appsync使用该包:

  • 安装Web版存储包:
    npm install @react-async-storage/async-storage --save
    
  • 在package.json中添加overrides配置(需npm 8.3及以上版本):
    "overrides": {
      "aws-appsync": {
        "@react-native-community/async-storage": "@react-async-storage/async-storage"
      }
    }
    
  • 本地执行npm ci验证,提交后重新部署

4. 升级Material UI依赖消除警告(可选)

旧版@material-ui/core@3.9.3不支持React 17,升级到4.x版本可消除peer依赖警告:

  • 执行命令:
    npm install @material-ui/core@4.1
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 04:10:19