From 7a6f1d20dbebe1a9de0b33019bf142588d235fa1 Mon Sep 17 00:00:00 2001 From: citizen204 Date: Sat, 13 Jun 2026 19:40:49 +0930 Subject: [PATCH 1/3] 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' }, }) From 798eb2884e0975398a33a33ec024da2522eb55bc Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Tue, 16 Jun 2026 11:26:19 +0200 Subject: [PATCH 2/3] chore: add changeset for ai-mcp CLI dynamic-require shim fix --- .changeset/mcp-cli-dynamic-require-shims.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/mcp-cli-dynamic-require-shims.md diff --git a/.changeset/mcp-cli-dynamic-require-shims.md b/.changeset/mcp-cli-dynamic-require-shims.md new file mode 100644 index 000000000..94d254d95 --- /dev/null +++ b/.changeset/mcp-cli-dynamic-require-shims.md @@ -0,0 +1,5 @@ +--- +"@tanstack/ai-mcp": patch +--- + +Fix `@tanstack/ai-mcp` CLI crashing on startup with `Error: Dynamic require of "fs" is not supported`. The CLI ships as an ESM bundle with `json-schema-to-typescript` inlined, which uses CJS `require()` internally. Enabling tsup's `shims` option injects a `createRequire(import.meta.url)` shim so those `require()` calls resolve correctly. From 9a70605aafd4fc4d9b0331ac41df3079e4af89aa Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2026 11:02:37 +0000 Subject: [PATCH 3/3] ci: apply automated fixes --- .changeset/mcp-cli-dynamic-require-shims.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/mcp-cli-dynamic-require-shims.md b/.changeset/mcp-cli-dynamic-require-shims.md index 94d254d95..f73bc8f7f 100644 --- a/.changeset/mcp-cli-dynamic-require-shims.md +++ b/.changeset/mcp-cli-dynamic-require-shims.md @@ -1,5 +1,5 @@ --- -"@tanstack/ai-mcp": patch +'@tanstack/ai-mcp': patch --- Fix `@tanstack/ai-mcp` CLI crashing on startup with `Error: Dynamic require of "fs" is not supported`. The CLI ships as an ESM bundle with `json-schema-to-typescript` inlined, which uses CJS `require()` internally. Enabling tsup's `shims` option injects a `createRequire(import.meta.url)` shim so those `require()` calls resolve correctly.