Skip to content

@clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

Description

@sethwebster

Summary

useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

…even though both packages are installed, listed in package.json, and being bundled by Metro.

Offending code

packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

Two problems:

  1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
  2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

Environment

  • @clerk/expo@3.1.9
  • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
  • Metro (default @expo/metro-config)
  • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
  • bun workspaces monorepo
  • iOS (dev client + simulator)

Repro

  1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

  2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

  3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

  4. Metro logs show both packages bundling successfully:

    iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
    iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
    
  5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

Current workaround

We ship a postinstall patch that rewrites the dynamic imports to require():

// scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

Proposed fix

Either (or both):

  1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

  2. At minimum, surface the real error:

    try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
    \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

    The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

Happy to open a PR if the direction is agreed.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    , 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
     blocks
    (function() {
    function addCopyButtons() {
    document.querySelectorAll('pre code').forEach(function(codeBlock) {
    if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
    codeBlock.parentElement.setAttribute('data-copy-added', 'true');
    var btn = document.createElement('button');
    btn.textContent = 'Copy';
    btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
    btn.onmouseover = function() { this.style.opacity = '1'; };
    btn.onmouseout = function() { this.style.opacity = '0.7'; };
    btn.onclick = function() {
    navigator.clipboard.writeText(codeBlock.textContent).then(function() {
    btn.textContent = 'Copied!';
    setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
    });
    };
    codeBlock.parentElement.style.position = 'relative';
    codeBlock.parentElement.appendChild(btn);
    });
    }
    addCopyButtons();
    // Re-run on dynamic content
    var observer = new MutationObserver(addCopyButtons);
    observer.observe(document.body, { childList: true, subtree: true });
    })();
    }
    } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
    })();
    (function(){
    try {
    var __m = "github.com";
    var __re = new RegExp('^' + "github\\.com" + '
    @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
    Skip to content

    @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

    Description

    @sethwebster

    Summary

    useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

    expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

    …even though both packages are installed, listed in package.json, and being bundled by Metro.

    Offending code

    packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

    letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

    Two problems:

    1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
    2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

    Environment

    • @clerk/expo@3.1.9
    • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
    • Metro (default @expo/metro-config)
    • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
    • bun workspaces monorepo
    • iOS (dev client + simulator)

    Repro

    1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

    2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

    3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

    4. Metro logs show both packages bundling successfully:

      iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
      iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
      
    5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

    Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

    Current workaround

    We ship a postinstall patch that rewrites the dynamic imports to require():

    // scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

    Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

    Proposed fix

    Either (or both):

    1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

    2. At minimum, surface the real error:

      try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
      \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

      The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

    Happy to open a PR if the direction is agreed.

    Related

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Type

      No type

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      , 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
      Skip to content

      @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

      Description

      @sethwebster

      Summary

      useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

      expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

      …even though both packages are installed, listed in package.json, and being bundled by Metro.

      Offending code

      packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

      letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

      Two problems:

      1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
      2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

      Environment

      • @clerk/expo@3.1.9
      • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
      • Metro (default @expo/metro-config)
      • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
      • bun workspaces monorepo
      • iOS (dev client + simulator)

      Repro

      1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

      2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

      3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

      4. Metro logs show both packages bundling successfully:

        iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
        iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
        
      5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

      Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

      Current workaround

      We ship a postinstall patch that rewrites the dynamic imports to require():

      // scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

      Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

      Proposed fix

      Either (or both):

      1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

      2. At minimum, surface the real error:

        try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
        \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

        The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

      Happy to open a PR if the direction is agreed.

      Related

      Metadata

      Metadata

      Assignees

      No one assigned

        Labels

        No labels
        No labels

        Type

        No type

        Projects

        No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        , 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
        Skip to content

        @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

        Description

        @sethwebster

        Summary

        useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

        expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

        …even though both packages are installed, listed in package.json, and being bundled by Metro.

        Offending code

        packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

        letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

        Two problems:

        1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
        2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

        Environment

        • @clerk/expo@3.1.9
        • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
        • Metro (default @expo/metro-config)
        • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
        • bun workspaces monorepo
        • iOS (dev client + simulator)

        Repro

        1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

        2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

        3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

        4. Metro logs show both packages bundling successfully:

          iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
          iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
          
        5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

        Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

        Current workaround

        We ship a postinstall patch that rewrites the dynamic imports to require():

        // scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

        Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

        Proposed fix

        Either (or both):

        1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

        2. At minimum, surface the real error:

          try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
          \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

          The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

        Happy to open a PR if the direction is agreed.

        Related

        Metadata

        Metadata

        Assignees

        No one assigned

          Labels

          No labels
          No labels

          Type

          No type

          Projects

          No projects

          Milestone

          No milestone

          Relationships

          None yet

          Development

          No branches or pull requests

          Issue actions

          , 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
          Skip to content

          @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

          Description

          @sethwebster

          Summary

          useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

          expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

          …even though both packages are installed, listed in package.json, and being bundled by Metro.

          Offending code

          packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

          letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

          Two problems:

          1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
          2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

          Environment

          • @clerk/expo@3.1.9
          • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
          • Metro (default @expo/metro-config)
          • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
          • bun workspaces monorepo
          • iOS (dev client + simulator)

          Repro

          1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

          2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

          3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

          4. Metro logs show both packages bundling successfully:

            iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
            iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
            
          5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

          Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

          Current workaround

          We ship a postinstall patch that rewrites the dynamic imports to require():

          // scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

          Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

          Proposed fix

          Either (or both):

          1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

          2. At minimum, surface the real error:

            try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
            \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

            The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

          Happy to open a PR if the direction is agreed.

          Related

          Metadata

          Metadata

          Assignees

          No one assigned

            Labels

            No labels
            No labels

            Type

            No type

            Projects

            No projects

            Milestone

            No milestone

            Relationships

            None yet

            Development

            No branches or pull requests

            Issue actions

            , 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
            Skip to content

            @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

            Description

            @sethwebster

            Summary

            useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

            expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

            …even though both packages are installed, listed in package.json, and being bundled by Metro.

            Offending code

            packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

            letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

            Two problems:

            1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
            2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

            Environment

            • @clerk/expo@3.1.9
            • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
            • Metro (default @expo/metro-config)
            • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
            • bun workspaces monorepo
            • iOS (dev client + simulator)

            Repro

            1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

            2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

            3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

            4. Metro logs show both packages bundling successfully:

              iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
              iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
              
            5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

            Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

            Current workaround

            We ship a postinstall patch that rewrites the dynamic imports to require():

            // scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

            Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

            Proposed fix

            Either (or both):

            1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

            2. At minimum, surface the real error:

              try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
              \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

              The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

            Happy to open a PR if the direction is agreed.

            Related

            Metadata

            Metadata

            Assignees

            No one assigned

              Labels

              No labels
              No labels

              Type

              No type

              Projects

              No projects

              Milestone

              No milestone

              Relationships

              None yet

              Development

              No branches or pull requests

              Issue actions

              , 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
              Skip to content

              @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch #8288

              Description

              @sethwebster

              Summary

              useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metro-runtime isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:

              expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser

              …even though both packages are installed, listed in package.json, and being bundled by Metro.

              Offending code

              packages/expo/src/hooks/useSSO.ts (built as dist/hooks/useSSO.js):

              letAuthSession;letWebBrowserModule;try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch{returnerrorThrower.throw("expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser");}

              Two problems:

              1. Dynamic import() from a published bundle is fragile under Metro. It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. @expo/metro-runtime not imported), the promise rejects and the real error never surfaces. A synchronous require() would be bundled into the main chunk and "just work". This is the same class of issue fixed for the RN QueryClient in fix(expo): synchronous QueryClient for React Native #8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.
              2. catch {} hides the real error. Even when the underlying failure is Unable to resolve module, @expo/metro-runtime is not installed, or a genuine TypeError, users see a generic "install these packages" message that sends them in the wrong direction.

              Environment

              • @clerk/expo@3.1.9
              • Expo SDK 55 (expo@^55.0.11, expo-router@~55.0.10)
              • Metro (default @expo/metro-config)
              • expo-auth-session@~55.0.13, expo-web-browser@~55.0.14 both installed
              • bun workspaces monorepo
              • iOS (dev client + simulator)

              Repro

              1. Bun-workspaces monorepo, @clerk/expo + expo-auth-session + expo-web-browser all correctly declared in apps/mobile/package.json.

              2. Don't import @expo/metro-runtime at the entry (it's not a declared dep of @clerk/expo or expo-router in this setup, so it's easy to miss).

              3. Call startSSOFlow({ strategy: 'oauth_google' }) from a screen.

              4. Metro logs show both packages bundling successfully:

                iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)
                iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)
                
              5. At runtime, the dynamic import() inside useSSO rejects and Clerk throws the "required for SSO" error.

              Root cause in our case: @expo/metro-runtime wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding import '@expo/metro-runtime' at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.

              Current workaround

              We ship a postinstall patch that rewrites the dynamic imports to require():

              // scripts/patch-clerk-expo-sso.mjsconstSNIPPET_FROM='[AuthSession, WebBrowserModule] = await Promise.all([import("expo-auth-session"), import("expo-web-browser")]);';constSNIPPET_TO=`AuthSession = require("expo-auth-session"); WebBrowserModule = require("expo-web-browser");`;

              Applied to node_modules/@clerk/expo/dist/hooks/useSSO.js and useOAuth.js. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.

              Proposed fix

              Either (or both):

              1. Prefer synchronous require() on native (same spirit as fix(expo): synchronous QueryClient for React Native #8087). expo-auth-session / expo-web-browser are tiny and already listed as optional peer deps — nothing is gained by deferring them. require() is Metro-safe and removes the async-chunk failure mode entirely.

              2. At minimum, surface the real error:

                try{[AuthSession,WebBrowserModule]=awaitPromise.all([import("expo-auth-session"),import("expo-web-browser"),]);}catch(e){returnerrorThrower.throw(
                \`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\`@expo/metro-runtime\\\` is imported at your app entry. Underlying error: \${e?.message ?? e}\`);}

                The catch {} is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.

              Happy to open a PR if the direction is agreed.

              Related

              Metadata

              Metadata

              Assignees

              No one assigned

                Labels

                No labels
                No labels

                Type

                No type

                Projects

                No projects

                Milestone

                No milestone

                Relationships

                None yet

                Development

                No branches or pull requests

                Issue actions