When importing a specific adapter function from the top-level package (@cloudflare/tanstack-ai), tree-shaking does not seem to work with bundlers like esbuild. As a result, unrelated adapters and their dependencies (such as @tanstack/ai-openrouter, @openrouter/sdk, @tanstack/ai-anthropic, and @tanstack/ai-grok) are bundled into the final output, unnecessarily increasing the bundle size by around 250KB.
Reproduction Steps
- Install the package:
npm install @cloudflare/tanstack-ai@0.2.1
- Import only a specific function (e.g.,
createGeminiChat) from the top level:
import { createGeminiChat } from '@cloudflare/tanstack-ai';
- Bundle using
esbuild with tree-shaking enabled:
esbuild --bundle --minify --tree-shaking=true --platform=browser --format=esm
Expected Behavior
Only createGeminiChat and its required dependencies should be bundled. Unused adapters like Anthropic, OpenRouter, and Grok should be tree-shaken out.
Actual Behavior
All available adapters are pulled into the bundle.
Currently, users have to deep-import directly from the specific adapter path to avoid this:
import { createGeminiChat } from '@cloudflare/tanstack-ai/adapters/gemini';
However, the top-level exports should ideally support proper tree-shaking without forcing deep imports.
Additional Context
This issue might be related to missing "sideEffects": false in package.json, or how the entry point is exported/compiled.
When importing a specific adapter function from the top-level package (
@cloudflare/tanstack-ai), tree-shaking does not seem to work with bundlers likeesbuild. As a result, unrelated adapters and their dependencies (such as@tanstack/ai-openrouter,@openrouter/sdk,@tanstack/ai-anthropic, and@tanstack/ai-grok) are bundled into the final output, unnecessarily increasing the bundle size by around 250KB.Reproduction Steps
createGeminiChat) from the top level:esbuildwith tree-shaking enabled:Expected Behavior
Only
createGeminiChatand its required dependencies should be bundled. Unused adapters like Anthropic, OpenRouter, and Grok should be tree-shaken out.Actual Behavior
All available adapters are pulled into the bundle.
Currently, users have to deep-import directly from the specific adapter path to avoid this:
However, the top-level exports should ideally support proper tree-shaking without forcing deep imports.
Additional Context
This issue might be related to missing
"sideEffects": falseinpackage.json, or how the entry point is exported/compiled.