Skip to content

fix: avoid Next.js Edge Runtime warnings in Node.js deprecation check #1520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mandarini
Copy link
Contributor

What kind of change does this PR introduce?

Bug fix - resolves Next.js Edge Runtime compatibility warnings

What is the current behavior?

The Node.js deprecation warning introduced in v2.52.1 causes Next.js Edge Runtime build warnings when using @supabase/supabase-js in middleware, even though the code is properly guarded and won't execute in Edge Runtime.

The warnings appear as:

A Node.js API is used (process.version at line: 17) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime

What is the new behavior?

This PR modifies the deprecation warning check to use dynamic property access (process['version']) instead of direct property access (process.version). This prevents Next.js static analysis from flagging the code as incompatible with Edge Runtime while maintaining the exact same runtime behavior.

Key changes:

  • Use dynamic property access to avoid static analysis warnings
  • Improved code comments for clarity
  • No functional changes - the deprecation warning still works exactly as intended

Additional context

Testing

  • All unit tests pass
  • Build completes successfully
  • The fix should prevent Next.js Edge Runtime warnings (to be verified in Next.js projects)

Use dynamic property access for process.version to prevent Next.js static
analysis from flagging the code as incompatible with Edge Runtime.

The deprecation warning logic remains unchanged - it only runs in actual
Node.js environments and is properly guarded against Edge Runtime execution.

Fixes supabase#1515
@mandarini mandarini marked this pull request as draft August 6, 2025 13:05
@coveralls
Copy link

coveralls commented Aug 6, 2025

Pull Request Test Coverage Report for Build 16778329417

Details

  • 6 of 7 (85.71%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+2.1%) to 74.8%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/index.ts 6 7 85.71%
Totals Coverage Status
Change from base Build 16571216493: 2.1%
Covered Lines: 122
Relevant Lines: 146

💛 - Coveralls

Maintain the original defensive programming checks while still using
dynamic property access to avoid Edge Runtime warnings
- Test browser environment detection
- Test Edge Runtime compatibility (no process object)
- Test various process.version states (undefined, null, invalid)
- Test version detection for Node.js 16, 18, 20, 22
- Test invalid version format handling
- Add export {} to make file a module
- Remove problematic test for undefined process (dependencies require it)
- Add comment explaining why Edge Runtime scenario is hard to test in Node
Use Object.defineProperty to mock only process.version instead of
spreading the entire process object. This avoids copying TTY handles
and other complex properties that cause Jest warnings.
@mandarini mandarini self-assigned this Aug 6, 2025
@mandarini mandarini marked this pull request as ready for review August 6, 2025 13:30
@mandarini mandarini requested a review from grdsdev August 6, 2025 13:30
@mandarini mandarini merged commit 4f38a9c into supabase:master Aug 7, 2025
13 checks passed
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.

Node.js 18 deprecation warning added in v2.52.1 causes Next.js Edge Runtime build warnings
3 participants