Current Behavior: I am deploying a Next.js monorepo using Turborepo. I need to run the build from inside the app directory (frontend/)so that Turbo can correctly hash the local Vercel environment files located in apps/frontend/.vercel/.env.*.local.
However, when I run vercel build from inside the frontend directory, Vercel appends the Project Setting “Root Directory” to the current path, resulting in a duplicate path error: Error: ENOENT: no such file or directory, lstat ‘…/Repo/frontend/frontend/.next/routes-manifest.json’
Expected Behavior: When running vercel build from the directory configured as the “Root Directory”, Vercel should detect that the context is already correct and look for artifacts in ./.next instead of appending the path again.
Code, configuration, and steps that reproduce this issue
- Directory Structure:
/ (Monorepo Root)
├── turbo.json
├
│ └── frontend/ (Configured as “Root Directory” in Vercel)
│ ├── next.config.js (Standard, no distDir override)
│ ├── .vercel/ (Contains .env.preview.local needed for Turbo inputs)
│ └── package.json - turbo.json (Why I need to be in the folder): My build task relies on hashing the specific Vercel env files local to the app.
JSON
{
“tasks”: {
“build”: {
“inputs”: [
“$TURBO_DEFAULT$”,
“.vercel/.env.preview.local”,
“.vercel/.env.production.local”
],
“outputs”: [“.next/", "!.next/cache/”]
}
}
} - Steps to Reproduce:
cd frontend
npx vercel pull (Downloads env vars to frontend/.vercel)
npx vercel build
Result: Build succeeds via Turbo, but Vercel CLI fails to find the output because it looks in frontend/frontend/.next. - What I’ve tried:
Running from Root: This fixes the path error, but Turbo fails to hash the environment files because they are nested inside frontend/.vercel and the root context doesn’t see them as inputs correctly.
Setting rootDirectory: null in project.json: Vercel forces the paths frontend/frontend/.next. If I set rootDirectory: test, it will be the correct path frontend/test
Project information
Framework: Next.js
Build Tool: Turborepo
Environment: Vercel CLI (Local Build)
Project Settings:
Framework Preset: Next.js
Root Directory: frontend
Output Directory: Default (Empty)
Build Command: cd ../.. && npx turbo run build --filter=frontend
I run the turbo build command from the monorepo’s root folder