Skip to content

fix(provider): handle bundled @aws-sdk/credential-providers module format#277

Closed
agustif wants to merge 1 commit intoLatitudes-Dev:devfrom
agustif:clean-fix
Closed

fix(provider): handle bundled @aws-sdk/credential-providers module format#277
agustif wants to merge 1 commit intoLatitudes-Dev:devfrom
agustif:clean-fix

Conversation

@agustif
Copy link

@agustif agustif commented Jan 7, 2026

Fixes issue where `fromNodeProviderChain` is not a function when
`@aws-sdk/credential-providers` is bundled by `BunProc.install()`.

The bundled module exports all functions via default export, not as
named exports. Update import to handle both bundled (default export)
and unbundled (named exports) formats.

Also use bearer token as apiKey when available to avoid unnecessary
credential provider import.

Greptile Summary

Fixed runtime error where fromNodeProviderChain was not a function when @aws-sdk/credential-providers is bundled by BunProc.install(). The bundled module exports functions via default export while unbundled uses named exports.

Key Changes:

  • Handle both bundled (default export) and unbundled (named exports) module formats using nullish coalescing: mod.default?.fromNodeProviderChain ?? mod.fromNodeProviderChain
  • Add error handling to throw if fromNodeProviderChain is not found in either format
  • Optimize by using bearer token as apiKey when available, avoiding unnecessary credential provider import
  • Add @aws-sdk/credential-providers@3.964.0 as direct dependency to ensure version compatibility

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix correctly addresses the bundled module import issue with proper fallback logic, includes appropriate error handling, and adds an optimization to skip credential provider imports when bearer token is available. The approach follows defensive coding practices by checking both export formats.
  • No files require special attention

Important Files Changed

Filename Overview
packages/opencode/src/provider/provider.ts Fixed bundled module import issue by handling both default and named exports for fromNodeProviderChain, added bearer token optimization to avoid unnecessary imports
package.json Added @aws-sdk/credential-providers 3.964.0 as a direct dependency to support credential provider functionality

Sequence Diagram

sequenceDiagram
    participant App as Amazon Bedrock Loader
    participant Config as Config/Env
    participant BunProc as BunProc.install()
    participant Module as @aws-sdk/credential-providers
    participant Provider as AmazonBedrockProvider

    App->>Config: Check AWS_BEARER_TOKEN_BEDROCK
    alt Bearer token available
        Config-->>App: Return bearer token
        App->>Provider: Create provider with apiKey
        Note over App,Provider: Skip credential provider import
    else No bearer token
        App->>BunProc: Install @aws-sdk/credential-providers
        BunProc-->>App: Return module path
        App->>Module: Import module
        alt Bundled module (default export)
            Module-->>App: mod.default.fromNodeProviderChain
        else Unbundled module (named export)
            Module-->>App: mod.fromNodeProviderChain
        end
        App->>App: Verify fromNodeProviderChain exists
        App->>Provider: Create provider with credentialProvider
    end
    Provider-->>App: Configured provider
Loading

…rmat

Fixes issue where fromNodeProviderChain is not a function when
@aws-sdk/credential-providers is bundled by BunProc.install().

The bundled module exports all functions via default export, not as
named exports. Update import to handle both bundled (default export)
and unbundled (named exports) formats.

Also use bearer token as apiKey when available to avoid unnecessary
credential provider import.

Co-authored-by: opencode <opencode@opencode.ai>
@shuv1337
Copy link
Collaborator

shuv1337 commented Jan 7, 2026

Thanks for the contribution! We appreciate you taking the time to identify and fix this issue.

However, we've already addressed this in our fork. Our implementation at packages/opencode/src/provider/provider.ts:200-221 handles the bundled module format with the same approach, plus an additional case for double-wrapped defaults that Bun can produce:

const fromNodeProviderChain =
  awsSdkModule.fromNodeProviderChain ??
  awsSdkModule.default?.fromNodeProviderChain ??
  awsSdkModule.default?.default?.fromNodeProviderChain

Closing as this is already resolved on our end, but thank you for the report!

— shuvbot

@shuv1337 shuv1337 closed this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants