evaluators icon indicating copy to clipboard operation
evaluators copied to clipboard

fix(typescript-sdk): prevent bundlers from requiring unused @ai-sdk providers

Open adnanrhussain opened this issue 5 months ago • 1 comments

Summary

Placeholder — will be expanded once the partner-reported issue is filed (link/Closes #___ to be added).

Consumers only need to install the @ai-sdk/* provider they actually use, but bundlers (Next.js/Turbopack, webpack, Vite/Rollup) statically resolve the SDK's dynamic import() specifiers at build time, so a build with only @ai-sdk/openai installed fails with Module not found: Can't resolve '@ai-sdk/anthropic' (and @ai-sdk/google').

This adds webpackIgnore / turbopackIgnore / @vite-ignore magic comments to the dynamic provider imports so bundlers leave them as runtime calls. The existing .catch() guard still produces a friendly "install its adapter" error if a selected provider isn't installed.

Validation

Reproduced and verified with a Next.js 16.2.6 app (only @ai-sdk/openai installed):

Before After
next build ❌ Module not found for @ai-sdk/anthropic + @ai-sdk/google ✅ compiles successfully

Build, lint, and 241/241 unit tests pass.

TODO before merge

  • [ ] Link the partner-reported issue (Closes #___)

adnanrhussain avatar Jun 15 '26 19:06 adnanrhussain

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Jun 15 '26 19:06 codecov[bot]