react-native icon indicating copy to clipboard operation
react-native copied to clipboard

refactor(dev-middleware): drop `node-fetch` in favor of Node built-in fetch

Open byCedric opened this issue 1 year ago • 5 comments

Summary:

Node 22 doesn't work well with node-fetch@2, as one of their polyfills is using the deprecated punycode module. This causes unnecessary warnings like:

image

Instead of upgrading to the much larger node-fetch@3, this change drops node-fetch in favor of Node's own built-in fetch implementation (using undici).

Note, @react-native/dev-middleware already has the engines.node >= 18 (which is required for fetch).

Changelog:

[GENERAL] [CHANGED] - Drop node-fetch in favor of Node's built-in fetch from undici in @react-native/dev-middleware

Test Plan:

See CI for passing tests

byCedric avatar Jun 30 '24 16:06 byCedric

Why would it fail on globalThis, it's the spec-guaranteed global 🙈

byCedric avatar Jun 30 '24 16:06 byCedric

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 20,366,100 -4
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 23,562,903 -5
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: c7988c9c82793b6b41d4c9190a28ce1202410fa0 Branch: main

analysis-bot avatar Jun 30 '24 16:06 analysis-bot

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Jun 30 '24 18:06 facebook-github-bot

@byCedric if we use this with Node 18, or Node 20, do we get experimental API warnings?

NickGerleman avatar Jul 02 '24 12:07 NickGerleman

@byCedric if we use this with Node 18, or Node 20, do we get experimental API warnings?

@NickGerleman No, there should not be any experimental warnings around fetch in the Node 18 or 20 (except versions older than Node 18.13.0 - released on Jan 6th, 2023):

Node 18.0.0 Node 18.20.3 Node 20.0.0
node-18.0.0 node-18.20.3 node-20.0.0

That warning was removed in Node 18.13.0, through PR 45287

byCedric avatar Jul 03 '24 01:07 byCedric

@robhogan merged this pull request in facebook/react-native@30a3e6e8dfcfc9597873578b8332ec027ccf1b84.

facebook-github-bot avatar Jul 03 '24 16:07 facebook-github-bot

This pull request was successfully merged by @byCedric in 30a3e6e8dfcfc9597873578b8332ec027ccf1b84.

When will my fix make it into a release? | How to file a pick request?

github-actions[bot] avatar Jul 03 '24 16:07 github-actions[bot]