fix(api): Vercel serverless handler + common CJS dual-build#32
Open
kuyacarlo wants to merge 7 commits into
Open
fix(api): Vercel serverless handler + common CJS dual-build#32kuyacarlo wants to merge 7 commits into
kuyacarlo wants to merge 7 commits into
Conversation
Production crashed on every request with ERR_REQUIRE_ESM: Nest emits CommonJS but @worksight/common was ESM-only, so require() of the workspace package killed the isolate. Dual-build common to dist/esm + dist/cjs and wire package exports accordingly. Also replace the broken "outputDirectory: dist" deploy (Vercel treated compiled files as functions, and main.ts called app.listen()) with a real serverless entry: api/index.js → dist/vercel.js over an Express adapter, rewrite /(.*) → /api. Local boot still uses main.ts + listen. Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Nest Swagger UI returned HTML but its local swagger-ui-dist CSS/JS never shipped in the serverless bundle (404). Stop mounting that UI. Expose OpenAPI at /openapi.json (and /api-json), put Scalar at /api and /reference, and keep a CDN-backed Swagger UI at /swagger. Co-authored-by: Cursor <cursoragent@cursor.com>
@scalar/nestjs-api-reference pulls ESM-only client-side-rendering and crashes the CJS Nest serverless bundle with ERR_REQUIRE_ESM on every request. Drop that dependency; serve Scalar and Swagger UI as small HTML shells that load their UIs from CDN against /openapi.json. Co-authored-by: Cursor <cursoragent@cursor.com>
The data-url + standalone.min.js shell rendered a blank page. Switch to
Scalar.createApiReference('#app', { url }) per current html-js docs.
Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the root hello handler (404s now). Add Nest Swagger decorators and DTO schemas for every remaining endpoint so Scalar/Swagger show request/response shapes, optional query params, and error responses. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #31. Fixes the live production crash.
Summary
ERR_REQUIRE_ESM— Nest CJSrequire('@worksight/common')against an ESM-only package. Every request →FUNCTION_INVOCATION_FAILED.@worksight/commonnow dual-buildsdist/esm+dist/cjswith correctexports.import/exports.require.api/index.js→dist/vercel.js(Express adapter, warm-cache). DroppedoutputDirectory: dist(that made Vercel treat every compiled file as a function).vercel.jsonrewrites/(.*)→/api.DATABASE_URL/DATABASE_URL_DIRECT/CORS_ORIGINSto the recreatedworksight-apiproject.Test plan
require('@worksight/common')and ESM import both loadpnpm --filter @worksight/api test— 19 green; web type-check greenGET /health→ 200database: postgresvercel --proddeploy returns 200 on/healthand/usersMade with Cursor