提示的构建错误信息为:
09:35:29.838 Error: Exit with error code: 1
09:35:29.839 at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
09:35:29.839 at Object.onceWrapper (node:events:652:26)
09:35:29.839 at ChildProcess.emit (node:events:537:28)
09:35:29.840 at ChildProcess._handle.onexit (node:internal/child_process:291:12)
09:35:29.847 Failed: build command exited with code: 1
原因和解决
提示上面错误信息的原因是 Yarn 的版本问题。
在默认 NodeJS 的安装情况下,Yarn 会安装 1.22 的版本。
但在cloudflare 构建中,默认会使用 Yarn 3 的版本。
在日志的最上部分,提示了安装 Yarn 的版本信息。
09:35:26.187 No wrangler.toml file found. Continuing.
09:35:26.253 Detected the following tools from environment: [email protected], [email protected]
因此解决办法就是针对 VitePress 项目指定使用 yarn 的版本。
运行命令来进行升级:
yarn set version stable
控制台输出:
PS D:\WorkDir\iSharkFly\iSharkFly-Cn\docs-hn> yarn set version stable
➤ YN0000: Downloading https://repo.yarnpkg.com/4.9.1/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-4.9.1.cjs
➤ YN0000: Done in 0s 195ms
PS D:\WorkDir\iSharkFly\iSharkFly-Cn\docs-hn> yarn -v
4.9.1
PS D:\WorkDir\iSharkFly\iSharkFly-Cn\docs-hn>
随后推送,重新部署即可。