This repository was archived by the owner on Oct 9, 2025. It is now read-only.
fix: prioritize ESM build in package exports to fix webpack warnings #481
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.
Fix webpack "Critical dependency" warnings by prioritizing ESM build
Updates package.json exports to default to the ESM build instead of CommonJS, resolving "Critical dependency: the request of a dependency is an expression" warnings in webpack builds.
Changes:
Tested on Next.js v15 with webpack (non-turbopack). Previous workaround required manual webpack config:
This exports change eliminates the need for manual webpack configuration by making bundlers prefer the ES2020 build that preserves dynamic imports.
Fixes: webpack "Critical dependency" warnings in issue #1437
What kind of change does this PR introduce?
Bug fix - Resolves webpack build warnings that appear when using @supabase/realtime-js with modern bundlers.
What is the current behavior?
When using @supabase/realtime-js with webpack-based builds (like Next.js without Turbopack), developers encounter:
Root cause: The current package.json exports default to the CommonJS build (
dist/main/) which uses ES2017 target. TypeScript transpiles cleanimport('@supabase/node-fetch')statements into complexPromise.resolve().then(require())patterns that webpack flags as problematic.Related issues:
What is the new behavior?
After this change:
dist/module/)import()statementsBundler resolution now works as:
"import"condition → uses ESM build (ES2020)require()uses"require"condition → uses CommonJS build (ES2017)Additional context
This is a zero-breaking-change fix that leverages the existing dual-build system. Both
dist/main/(CommonJS) anddist/module/(ESM) builds already exist - we're just changing which one bundlers prefer by default.Alternative solutions considered:
realtimeClient.ts
Comments:
Environment testing:
Benefits: