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

NextJS 13部署至Vercel后API接口返回404求助

NextJS 13部署到Vercel后API接口持续返回404求助

有没有开发者遇到过类似问题?我用NextJS 13开发的应用,本地环境调用API接口完全正常,但部署到Vercel平台后,向API端点发送GET请求时一直返回404错误。

哪怕是NextJS默认提供的简单API也出现这个问题:

默认API示例

路径:pages/api/hello

export default async function handler(req, res) {
  res.status(200).json({
    name: 'John Doe',
  })
}

package.json配置

{
  "name": "my-next-js-sample"
  "version": "0.1.1",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "axios": "^1.1.3",
    "cheerio": "^1.0.0-rc.12",
    "dayjs": "^1.11.6",
    "firebase": "^9.13.0",
    "next": "13.0.0",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "eslint": "8.26.0",
    "eslint-config-next": "13.0.0"
  }
}

项目目录结构

项目目录结构

API调用示例

http://localhost:3000/api/hello
http://localhost:3000/api/v2/live

本地开发环境下所有API路由都能正常调用。

Vercel项目设置

Vercel项目设置

内容的提问来源于stack exchange,提问作者Chan Lay

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 22:46:04