Skip to content

fix: output Vercel serverless function to dist/api/ to match outputDirectory - #1004

Merged
hotlong merged 2 commits into
mainfrom
copilot/fix-output-directory-mismatch
Mar 31, 2026
Merged

fix: output Vercel serverless function to dist/api/ to match outputDirectory#1004
hotlong merged 2 commits into
mainfrom
copilot/fix-output-directory-mismatch

Conversation

CopilotAI commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

All /api/* requests on Vercel return SPA HTML instead of invoking the serverless function. bundle-api.mjs emits api/index.js at the project root, but vercel.json sets outputDirectory: "dist" — so the function is outside the deployment tree and Vercel falls back to the SPA rewrite.

Changes

  • apps/studio/scripts/bundle-api.mjsoutfile: 'api/index.js'outfile: 'dist/api/index.js'
  • apps/studio/vercel.json — Add explicit functions config declaring api/index.js with @vercel/node@3 runtime
  • apps/studio/.gitignore — Remove api/index.js / api/index.js.map entries (now under dist/, already ignored)
  • Changeset + CHANGELOG — Updated to reflect the actual root cause

@vercel

vercelBot commented Mar 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
objectstack-playReadyReadyPreview, CommentMar 31, 2026 4:07am
specReadyReadyPreview, CommentMar 31, 2026 4:07am

Request Review

…outputDirectory
The bundle-api.mjs script was emitting api/index.js at the project root, but
vercel.json sets outputDirectory: "dist" — so Vercel could not discover the
serverless function and fell back to the SPA HTML route for all /api/* requests.
- Change esbuild outfile from api/index.js to dist/api/index.js
- Add explicit functions config in vercel.json with @vercel/node@3 runtime
- Remove obsolete .gitignore entries for api/index.js (now under dist/)
- Update changeset and CHANGELOG
Fixes#1002
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/24bf6f10-3ca1-4cff-a9cb-c6c0905d1845
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
CopilotAI changed the title [WIP] Fix output directory mismatch for Vercel API functionsfix: output Vercel serverless function to dist/api/ to match outputDirectoryMar 31, 2026
CopilotAI requested a review from hotlongMarch 31, 2026 03:50
@hotlong
hotlong marked this pull request as ready for review March 31, 2026 03:53
CopilotAI review requested due to automatic review settings March 31, 2026 03:53
@hotlong
hotlong merged commit 9f8bb6f into mainMar 31, 2026
3 of 5 checks passed

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Studio’s Vercel deployment so /api/* requests invoke the bundled serverless function instead of falling back to the SPA HTML, by ensuring the function entrypoint is emitted inside the configured Vercel outputDirectory.

Changes:

  • Update the API bundle output path to dist/api/index.js so it is included in the Vercel build output.
  • Add an explicit functions declaration in apps/studio/vercel.json for api/index.js using @vercel/node@3.
  • Remove obsolete .gitignore entries for the old non-dist/ API bundle location; update changeset + root changelog to reflect the real root cause.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
CHANGELOG.mdDocuments the Vercel API HTML fallback root cause and the corrective deployment changes.
apps/studio/vercel.jsonEnsures Vercel recognizes the serverless function under the dist/ output via explicit functions config.
apps/studio/scripts/bundle-api.mjsEmits the bundled serverless function into dist/api/index.js to match outputDirectory.
apps/studio/.gitignoreRemoves ignores for the old api/index.js(.map) location now that output is under dist/.
.changeset/fix-vercel-api-html-response.mdUpdates the release note to match the actual cause and fix (output location + functions config).

Comment threadCHANGELOG.md
Comment on lines +42 to +47
### Fixed
- **Vercel API always returns HTML — serverless function entrypoint not found** — The `bundle-api.mjs`
script was emitting `api/index.js` at the project root, but `vercel.json` sets `outputDirectory: "dist"`,
so Vercel could not discover the serverless function and fell back to the SPA HTML route for all
`/api/*` requests. Changed esbuild `outfile` to `dist/api/index.js` and added explicit `functions`
config in `vercel.json` with `@vercel/node@3` runtime.

CopilotAIMar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are now two separate ### Fixed sections under the [Unreleased] heading (this one and another later in the same section). Consider moving this new bullet into the existing [Unreleased]### Fixed section to keep the changelog structure consistent and easier to scan.

Copilot uses AI. Check for mistakes.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vercel API always returns HTML: serverless function entrypoint not found due to outputDirectory mismatch

3 participants

@hotlong