fix: prefer native fetch over node-fetch to eliminate url.parse() deprecation warning #59
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.
Problem
Node.js 18+ users see this deprecation warning when using the SDK:
This warning originates from
node-fetchv2.x, which internally uses the deprecatedurl.parse()API.Solution
Update
safeFetch.tsto check for nativefetchavailability before attempting to loadnode-fetch. Since Node.js 18+ includes native fetch, this eliminates the need fornode-fetchentirely in modern environments.Changes
src/utils/safeFetch.ts: Check for native fetch first, only fall back to node-fetch when native fetch is unavailablesrc/__tests__/jest.setup.js: Deleteglobal.fetchin tests so existing node-fetch mocks continue to worksrc/utils/__tests__/safeFetch.test.ts: New tests to verify the native fetch preference behaviorBehavior by Environment
Test Results
All 326 tests pass (excluding the expected
ClientInitializeResponseConsistencyfailure for non-Statsig employees).Backward Compatibility