Skip to content

Commit df40512

Browse files
citizen204AlemTuzlakautofix-ci[bot]
authored
fix(ai-mcp): add shims to bin bundle for CJS dynamic-require compat (#754)
* 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 * chore: add changeset for ai-mcp CLI dynamic-require shim fix * ci: apply automated fixes --------- Co-authored-by: Alem Tuzlak <t.zlak@hotmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 4041c2f commit df40512

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/ai-mcp': patch
3+
---
4+
5+
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.

packages/ai-mcp/tsup.bin.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ export default defineConfig({
1010
noExternal: ['json-schema-to-typescript', 'jiti'],
1111
// Keep the heavy SDK + workspace pkg external (installed alongside).
1212
external: ['@modelcontextprotocol/sdk', '@tanstack/ai'],
13+
// json-schema-to-typescript uses CJS dynamic require(); shims injects
14+
// createRequire so those calls work inside this ESM bundle.
15+
shims: true,
1316
banner: { js: '#!/usr/bin/env node' },
1417
})

0 commit comments

Comments
 (0)