Skip to content

[tanstack-ai] bug: Tree-shaking not working when importing from the top-level package #609

Description

@L4Ph

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:
npm install @cloudflare/tanstack-ai@0.2.1
  1. Import only a specific function (e.g., createGeminiChat) from the top level:
import { createGeminiChat } from '@cloudflare/tanstack-ai';
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions