![[Bug] cloudflare部署时无法访问华为云](https://www.chat-gpts.plus/wp-content/uploads/2026/06/6611-08b1ee3a.jpg)
[Bug] cloudflare部署时无法访问华为云
快速结论:该报错通常发生在 Cloudflare 构建环境中,yarn 从华为云镜像(mirrors.huaweicloud.com)拉取 npm 包时网络超时。优先排查 yarn.lock 中是否将 resolved URL 指向了华为云镜像,并将其替换回官方 npm registry。
问题场景
用户在 Cloudflare 部署 NextChat(版本 995bef7)时,yarn install 阶段从华为云镜像拉取 caniuse-lite 包超时,导致构建失败。触发环境为 Cloudflare Pages 或其他 Cloudflare 构建服务。
报错原文
13:56:19.979 | [2/4] Fetching packages...
13:56:24.521 | error An unexpected error occurred: "https://mirrors.huaweicloud.com/repository/npm/caniuse-lite/-/caniuse-lite-1.0.30001724.tgz: Socket connection timeout".
13:56:24.521 | info If you think this is a bug, please open a bug report with the information provided in "/opt/buildhome/repo/yarn-error.log".
13:56:24.522 | info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
13:57:29.001 | Error: Exit with error code: 1
13:57:29.001 | at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
13:57:29.001 | at Object.onceWrapper (node:events:652:26)
13:57:29.001 | at ChildProcess.emit (node:events:537:28)
13:57:29.001 | at ChildProcess._handle.onexit (node:internal/child_process:291:12)
13:57:29.016 | Failed: build command exited with code: 1
13:57:30.075 | Failed: error occurred while running build command
原因分析
根本原因是 yarn.lock 文件中某些包(例如 caniuse-lite)的 resolved 字段被指向了华为云镜像地址 https://mirrors.huaweicloud.com/...,而 Cloudflare 构建环境无法在该镜像上建立稳定的网络连接,导致 socket 超时。该问题属于代理/镜像网络问题,而非 NextChat 代码逻辑错误。
环境排查
- 确认部署平台为 Cloudflare(Pages 或 Workers 构建环境)
- 确认
yarn.lock文件中是否存在指向mirrors.huaweicloud.com的 resolved 地址 - 确认本地或其它构建环境是否能够正常访问华为云镜像(用于对比)
解决步骤
- 打开项目根目录下的
yarn.lock文件。 - 搜索
mirrors.huaweicloud.com,找到所有出现该镜像的resolved字段。 - 将每个
resolved值从https://mirrors.huaweicloud.com/...替换为官方 npm registry 地址https://registry.npmjs.org/...。例如:
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001724.tgz" - 保存
yarn.lock文件并重新提交到仓库。 - 在 Cloudflare 构建环境中重新触发部署(或重新运行
yarn install测试)。
可优先尝试:如果不想手动修改 yarn.lock,可以尝试在构建脚本中设置 yarn install --registry=https://registry.npmjs.org/,但这可能不适用于已固化的 lock 文件。
验证方法
重新运行 Cloudflare 构建,观察 yarn install 阶段是否成功完成所有包的下载,不再出现 Socket connection timeout 错误,且构建任务以 Exit code: 0 结束。



