fix(typescript-sdk): prevent bundlers from requiring unused @ai-sdk providers#105
Open
adnanrhussain wants to merge 1 commit into
Open
fix(typescript-sdk): prevent bundlers from requiring unused @ai-sdk providers#105adnanrhussain wants to merge 1 commit into
adnanrhussain wants to merge 1 commit into
Conversation
8bcfb82 to
64b700a
Compare
There was a problem hiding this comment.
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-ignoremagic 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 dynamicimport()specifiers at build time, so a build with only@ai-sdk/openaiinstalled fails withModule not found: Can't resolve '@ai-sdk/anthropic'(and@ai-sdk/google').This adds
webpackIgnore/turbopackIgnore/@vite-ignoremagic 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/openaiinstalled):next buildModule not foundfor@ai-sdk/anthropic+@ai-sdk/googleBuild, lint, and 241/241 unit tests pass.
TODO before merge
Closes #___)