Skip to content

fix(tempo): await accounts import instead of chaining .catch()#5202

Draft
singhlovepreet9 wants to merge 1 commit into
wevm:mainfrom
singhlovepreet9:fix-tempo-import-catch
Draft

fix(tempo): await accounts import instead of chaining .catch()#5202
singhlovepreet9 wants to merge 1 commit into
wevm:mainfrom
singhlovepreet9:fix-tempo-import-catch

Conversation

@singhlovepreet9

Copy link
Copy Markdown

Fixes #5201.

Problem

The Tempo connectors (webAuthn / tempoWallet / dangerous_secp256k1) in @wagmi/core lazily load the peer-installed accounts package with:

async function getAccountsModule() {
  return await import(
    /* turbopackOptional: true */
    'accounts'
  ).catch(() => {
    throw new Error('dependency "accounts" not found')
  })
}

Chaining .catch() directly on the result of import() assumes that value is always a spec-compliant native Promise. That isn't guaranteed in every bundling environment — notably under Metro (React Native's bundler), a transformed import() reliably exposes .then() but not .catch(). Evaluating import('accounts').catch then throws TypeError: undefined is not a function before the import settles and before the intended 'dependency "accounts" not found' message can run, making the connectors unusable there with a misleading error.

Fix

Await the dynamic import inside a try/catch instead of chaining .catch() on it. await only requires a thenable's .then(), so it works with Metro's non-spec import result while remaining identical for spec Promises. The /* turbopackOptional: true */ magic comment and the rethrown error message are preserved.

Verification

  • biome check on the changed file — clean.
  • tsc --noEmit (core) and the build:esm+types build — both pass.
  • Mechanism reproduced standalone (a thenable with .then but no .catch, mirroring Metro):
    • old path thenable.catch(...)TypeError: ...catch is not a function
    • new path await thenable → resolves normally

Note for reviewers (tests)

The template asks for a test that fails without the fix. I was unable to add one that's meaningful in CI: under Node/Vitest, import() always returns a spec-compliant Promise (with .catch) and accounts is installed in the workspace, so both the old and new code behave identically in the test environment — the divergence only appears under Metro's non-spec import() transform, which the repo's test runner can't reproduce. The change is a behavior-preserving 3-line refactor for spec Promises; happy to add a test if you can suggest a way to simulate the Metro import shape within the existing suite.

Chaining .catch() directly on the result of import() assumes that value
is always a spec-compliant Promise. Under bundlers where a transformed
import() returns a thenable with .then() but no .catch() (e.g. Metro /
React Native), evaluating .catch throws "TypeError: undefined is not a
function" before the intended error handler ever runs.

Await the dynamic import inside try/catch instead, since await only
requires a thenable's .then().
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

@singhlovepreet9 is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: caf4652

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@wagmi/core Patch
@wagmi/connectors Patch
wagmi Patch
@wagmi/solid Patch
@wagmi/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

tempo: getAccountsModule chains .catch() on import(), breaking under bundlers where dynamic import isn't a spec Promise (e.g. Metro/React Native)

1 participant