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

如何解决Vercel部署网站时出现的‘Invalid project directory’错误?

Vercel部署报错:Invalid project directory provided 解决方法

我已成功修改应用页面并推送到Git,但在Vercel平台部署网站时遇到如下错误:

Invalid project directory provided, no such directory: /vercel/path0/run?

我的next.config.js配置如下:

/** @type {import('next').NextConfig} */
module.exports = {
  reactStrictMode: true,
  swcMinify: true,
  trailingSlash: true,
  output: 'export',
  staticPageGenerationTimeout: 1000,
  serverRuntimeConfig: {
    PROJECT_ROOT: __dirname,
  },
  images: {
    domains: [
      'res.cloudinary.com',
      'avatars.githubusercontent.com',
      'lh3.googleusercontent.com',
      'www.instagram.com',
    ],
  },
}

解决步骤

1. 修正Vercel项目根目录配置

登录Vercel控制台进入项目设置:

  • 找到「General」标签下的「Build & Development Settings」
  • 检查「Root Directory」字段,不要填写run这类不存在的路径。如果项目直接在Git仓库根目录,留空即可;若在子文件夹,填写对应子目录路径。

2. 删除冲突的配置项

你启用了output: 'export'静态导出模式,但serverRuntimeConfig是给服务器端渲染(SSR)用的配置,静态模式下会触发冲突。删除serverRuntimeConfig部分,修改后的配置如下:

/** @type {import('next').NextConfig} */
module.exports = {
  reactStrictMode: true,
  swcMinify: true,
  trailingSlash: true,
  output: 'export',
  staticPageGenerationTimeout: 1000,
  images: {
    domains: [
      'res.cloudinary.com',
      'avatars.githubusercontent.com',
      'lh3.googleusercontent.com',
      'www.instagram.com',
    ],
  },
}

3. 重新触发部署

  • 将修改后的配置推送到Git仓库
  • 在Vercel控制台找到对应部署记录,点击「Redeploy」并选择「Clear build cache and deploy」,确保用新配置和干净缓存重新构建。

4. 检查Git仓库结构

确认Git仓库根目录下存在package.json、next.config.js等核心文件,没有多余的run文件夹或错误目录结构导致Vercel无法识别项目入口。

内容的提问来源于stack exchange,提问作者Vibhor Gupta

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 01:55:06