Skip to content

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

Open
adnanrhussain wants to merge 1 commit into
mainfrom
ahussain/optional-provider-imports
Open

fix(typescript-sdk): prevent bundlers from requiring unused @ai-sdk providers#105
adnanrhussain wants to merge 1 commit into
mainfrom
ahussain/optional-provider-imports

Conversation

@adnanrhussain

Copy link
Copy Markdown
Contributor

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 adnanrhussain added area: typescript-sdk javascript Pull requests that update javascript code labels Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the TypeScript SDK’s VercelAIProvider to ensure consumer bundlers don’t statically resolve (and therefore require installation of) unused @ai-sdk/* provider packages when encountering the provider’s dynamic import() calls.

Changes:

  • Add webpackIgnore, turbopackIgnore, and @vite-ignore magic comments to the dynamic imports for @ai-sdk/openai, @ai-sdk/anthropic, and @ai-sdk/google.
  • Expand the getModel() JSDoc to document the bundler behavior and why these comments are required.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
sdks/typescript/src/providers/ai-sdk-provider.ts 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: typescript-sdk javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants