AWS Amplify构建流水线中Yarn Install报304 Not Modified失败
AWS Amplify构建流程中Yarn Install失败问题解决
问题现象
构建过程中Yarn Install步骤报错,日志输出:
2024-12-17T13:07:25.673Z [WARNING]: error An unexpected error occurred: "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz: Request failed \"304 Not Modified\"" 2024-12-17T13:07:25.677Z [INFO]: info If you think this is a bug, please open a bug report with the information provided in "yarn-error.log"
环境信息
- AWS Amplify Hosting
- 包管理命令:
yarn install --frozen-lockfile
已尝试操作
- 在安装命令中添加
--no-cache参数:yarn install --frozen-lockfile --no-cache - 在amplify.yml中加入缓存清理步骤:
version: 1 frontend: phases: preBuild: commands: - yarn cache clean - yarn install --frozen-lockfile build: commands: - yarn run build artifacts: baseDirectory: .next files: - '**/*' cache: paths: - .next/cache/**/* - node_modules/**/*
可行解决方案
1. 禁用Amplify全局缓存
Amplify的内置缓存可能与Yarn缓存产生冲突,修改amplify.yml移除cache配置块:
version: 1 frontend: phases: preBuild: commands: - yarn cache clean - yarn install --frozen-lockfile build: commands: - yarn run build artifacts: baseDirectory: .next files: - '**/*'
2. 升级/更换Yarn版本
若使用Yarn 1.x,尝试升级至最新稳定版,或切换到Yarn Berry(2.x及以上),在preBuild阶段指定版本:
preBuild: commands: - npm install -g yarn@latest - yarn cache clean - yarn install --frozen-lockfile
3. 更新lockfile中的cssesc版本
手动编辑yarn.lock文件,将cssesc的版本更新至3.0.0以上的兼容版本(如3.0.1),提交修改后的lockfile到代码仓库后重新触发构建。
4. 限制网络并发(临时方案)
添加--network-concurrency 1参数限制请求并发数,规避304错误:
yarn install --frozen-lockfile --network-concurrency 1
内容的提问来源于stack exchange,提问作者Minhaj T
相关产品推荐
相关产品推荐

