Skip to content

Remove node-fetch dependency from @segment/analytics-node#1348

Open
MichaelGHSeg wants to merge 5 commits intomasterfrom
remove-node-fetch
Open

Remove node-fetch dependency from @segment/analytics-node#1348
MichaelGHSeg wants to merge 5 commits intomasterfrom
remove-node-fetch

Conversation

@MichaelGHSeg
Copy link
Collaborator

Summary

  • Removes node-fetch dependency since the package requires Node >= 20, which has native globalThis.fetch
  • The node-fetch fallback in fetch.ts was dead code — all supported platforms (Node 20+, Vercel Edge, Cloudflare Workers, browsers) provide native fetch
  • Simplifies fetch.ts to directly use globalThis.fetch
  • Removes node-fetch type compatibility test from typedef-tests

Motivation

Modernize dependencies — node-fetch is unnecessary since the Node 20 minimum version requirement was established. Customers (e.g. Atlassian via Flex SDK) are asking for reduced/modernized dependency trees.

Test plan

  • All 18 existing test suites pass (114 tests)
  • TypeScript compilation passes across all packages
  • Build succeeds (CJS + ESM)
  • Pre-push hook passes (full monorepo tsc check)

🤖 Generated with Claude Code

MichaelGHSeg and others added 2 commits February 25, 2026 11:26
Since the package requires Node >= 20 (which has native globalThis.fetch),
the node-fetch fallback in fetch.ts was dead code that never executed.
All supported platforms (Node 20+, Vercel Edge, Cloudflare Workers, browsers)
provide native fetch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2026

🦋 Changeset detected

Latest commit: ff2f3b2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-node Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.31%. Comparing base (6567607) to head (ff2f3b2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1348      +/-   ##
==========================================
+ Coverage   91.23%   91.31%   +0.08%     
==========================================
  Files         163      163              
  Lines        4393     4388       -5     
  Branches     1055     1052       -3     
==========================================
- Hits         4008     4007       -1     
+ Misses        385      381       -4     
Flag Coverage Δ
browser 92.21% <ø> (ø)
core 90.16% <ø> (ø)
node 88.52% <100.00%> (+0.59%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request removes the node-fetch dependency from @segment/analytics-node since the package requires Node >= 20, which has native globalThis.fetch support. The node-fetch fallback logic was dead code as all supported platforms (Node 20+, Vercel Edge, Cloudflare Workers, browsers) provide native fetch.

Changes:

  • Simplified fetch.ts to directly use globalThis.fetch without fallback logic
  • Removed node-fetch from package dependencies
  • Updated typedef tests to remove node-fetch compatibility test

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
packages/node/src/lib/fetch.ts Simplified fetch implementation to directly use globalThis.fetch, removing node-fetch fallback and EdgeRuntime checks
packages/node/package.json Removed node-fetch dependency from dependencies list
packages/node/src/tests/typedef-tests.ts Removed HTTPFetchFn import and node-fetch compatibility test, updated test description
yarn.lock Updated lockfile to reflect node-fetch removal from @segment/analytics-node dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mschasz
mschasz previously approved these changes Feb 25, 2026
@@ -0,0 +1,5 @@
---
'@segment/analytics-node': patch
Copy link
Contributor

@silesky silesky Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a major version bump?

Copy link
Contributor

@silesky silesky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a major version bump?

@silesky silesky self-requested a review February 26, 2026 04:50
Someone on Node < 18 ignoring the engines field would break since
node-fetch is no longer bundled as a fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
silesky
silesky previously approved these changes Feb 26, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

4 participants