▲ You are using Node.js 18.17.1. For Next.js,
Node.js version "^18.18.0 || ^19.8.0 || >= 20.0.0" is required.
▲ Error: Command "npm run build" exited with 1
Failed: Error while executing user command. Exited with error code: 1
Failed: build command exited with code: 1
Failed: error occurred while running build command
问题所在:
-
Cloudflare Pages 的默认构建环境使用的是 Node.js 18.17.1
-
但你的 Next.js 项目需要更新的 Node.js 版本(至少 18.18.0)
解决方案:
在 Cloudflare Pages 的项目设置中,你需要:
# 在构建设置中添加环境变量
NODE_VERSION=20.0.0 # 或 18.18.0
cloudflare添加环境变量
1、
2、
3、
4、成功
5、 打开网页你会发现有新的问题
ps:我用的npx create-next-app@latest 创建项目的,一开始使用低一点版本的nextjs 应该也可以。