fix rebuild for serverless

This commit is contained in:
Fredrik Jensen 2025-12-06 15:25:21 +01:00
parent 76fbc07343
commit 8f439f8ab7
3 changed files with 11 additions and 5 deletions

2
package-lock.json generated
View File

@ -4004,7 +4004,7 @@
},
"packages/library": {
"name": "mcp-ui-kit",
"version": "1.0.0",
"version": "1.0.2",
"license": "MIT",
"dependencies": {
"@mcp-ui/server": "^5.15.0",

View File

@ -1,6 +1,6 @@
{
"name": "mcp-ui-kit",
"version": "1.0.0",
"version": "1.0.2",
"description": "MCP UI Kit - Create rich UI components for MCP servers",
"type": "module",
"main": "./dist/server/index.cjs",

View File

@ -28,14 +28,20 @@ export async function bundleComponent(entryPath: string): Promise<string> {
}
let result: esbuild.BuildResult<{ write: false }>;
try {
result = await runBuild(entryPath);
} catch (error) {
// Handle "The service was stopped" error in serverless environments (Vercel, Lambda, etc.)
// Handle esbuild service errors in serverless environments (Vercel, Lambda, etc.)
// This happens when the serverless runtime freezes/stops the esbuild subprocess.
// Error messages vary: "service was stopped", "service is no longer running", etc.
// esbuild automatically restarts its service on the next call, so we just retry.
if (error instanceof Error && error.message.includes('service was stopped')) {
const isServiceError = error instanceof Error && (
error.message.includes('service was stopped') ||
error.message.includes('service is no longer running') ||
error.message.includes('The service')
);
if (isServiceError) {
result = await runBuild(entryPath);
} else {
throw error;