[tanstack-ai] bug: Tree-shaking not working when importing from the top-level package
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 345
- Avg merge
- 13h 31m
- Merged PRs (30d)
- 1
Description
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
1. Install the package:
```bash
npm install @cloudflare/tanstack-ai@0.2.1
```
2. Import only a specific function (e.g., `createGeminiChat`) from the top level:
```typescript
import { createGeminiChat } from '@cloudflare/tanstack-ai';
```
3. Bundle using `esbuild` with tree-shaking enabled:
```bash
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:
```typescript
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.
Contributor guide
Research direction
Start with package.json and the top-level exports for @cloudflare/tanstack-ai, then reproduce the bundle with esbuild using the createGeminiChat import shown in the issue. Compare the top-level and adapters/gemini builds; done means unused Anthropic, OpenRouter, and Grok adapters and dependencies are absent from the bundled output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100