Skip to content

Conversation

@mandarini
Copy link
Contributor

@mandarini mandarini commented Aug 11, 2025

What kind of change does this PR introduce?

Feature enhancement that provides a solution to bundler warnings while maintaining backward compatibility for Node.js < 22 users.

What is the current behavior?

Users see "Critical dependency: the request of a dependency is an expression" warnings in their bundlers due to dynamic imports in @supabase/realtime-js used for Node.js WebSocket detection.

What is the new behavior?

This PR introduces dual export paths to give users control over their build output:

📦 Main Export - Clean & Bundler-Friendly

import { createClient } from '@supabase/supabase-js'
-  No bundler warnings
-  Optimal for production builds
- ⚠️ Node.js < 22 users must provide WebSocket explicitly

🔧 Auto Export - Backward Compatible (Temporary)

import { createClient } from '@supabase/supabase-js/auto'
-  Maintains current behavior with auto-detection
- ⚠️ Will show bundler warnings
- 🚨 **Deprecated** - Will be removed in v3.0.0

Breaking Changes

None for most users! However, Node.js < 22 users using the main export will need to provide WebSocket:

// Before
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(url, key)

// After (Node.js < 22 only)
import { createClient } from '@supabase/supabase-js'
import ws from 'ws'
const supabase = createClient(url, key, {
  realtime: {
    transport: ws
  }
})

User Impact & Migration

Environment Impact Action Required
Browser None No changes
Edge Runtime None No changes
Node.js 22+ None No changes
Node.js < 22 Minor Install ws and pass via options OR use /auto export

Implementation Details

  • Updates @supabase/realtime-js to v2.16.0 with dual export support
  • Adds /auto export path in package.json
  • Creates SupabaseClient.auto.ts for backward compatibility
  • Main export uses clean realtime-js without dynamic imports
  • Auto export maintains dynamic imports for compatibility

Migration Timeline

  • v2.x: Both exports available
  • v3.0: Remove /auto export, require explicit transport for Node.js < 22

Related PRs

@coveralls
Copy link

coveralls commented Aug 11, 2025

Pull Request Test Coverage Report for Build 16887185443

Details

  • 0 of 74 (0.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-25.1%) to 49.734%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/index.auto.ts 0 14 0.0%
src/SupabaseClient.auto.ts 0 60 0.0%
Totals Coverage Status
Change from base Build 16805913259: -25.1%
Covered Lines: 122
Relevant Lines: 220

💛 - Coveralls

@mandarini mandarini self-assigned this Aug 11, 2025
@mandarini mandarini changed the title feat: update realtime-js to 2.16.0 feat: Dual export pattern for clean bundler builds and Node.js compatibility Aug 11, 2025
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.

3 participants