From 7a6f1d20dbebe1a9de0b33019bf142588d235fa1 Mon Sep 17 00:00:00 2001 From: citizen204 Date: Sat, 13 Jun 2026 19:40:49 +0930 Subject: [PATCH] fix(ai-mcp): add shims to bin bundle for CJS dynamic-require compat json-schema-to-typescript (inlined via noExternal) uses dynamic require() calls internally. When bundled into an ESM output the global require is absent, causing the CLI to crash on startup with "Dynamic require of 'fs' is not supported" before it can parse any args. shims: true makes tsup inject a createRequire-based shim at the top of the bundle so CJS dependencies can call require() safely from within the ESM output. Fixes #753 --- packages/ai-mcp/tsup.bin.config.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/ai-mcp/tsup.bin.config.ts b/packages/ai-mcp/tsup.bin.config.ts index e5635420d..d038360cd 100644 --- a/packages/ai-mcp/tsup.bin.config.ts +++ b/packages/ai-mcp/tsup.bin.config.ts @@ -10,5 +10,8 @@ export default defineConfig({ noExternal: ['json-schema-to-typescript', 'jiti'], // Keep the heavy SDK + workspace pkg external (installed alongside). external: ['@modelcontextprotocol/sdk', '@tanstack/ai'], + // json-schema-to-typescript uses CJS dynamic require(); shims injects + // createRequire so those calls work inside this ESM bundle. + shims: true, banner: { js: '#!/usr/bin/env node' }, })