Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: resolve punycode deprecation warning by updating whatwg-url#1861

Open
veeceey wants to merge 2 commits intonode-fetch:2.xfrom
veeceey:fix/issue-1826-punycode-deprecation
Open

fix: resolve punycode deprecation warning by updating whatwg-url#1861
veeceey wants to merge 2 commits intonode-fetch:2.xfrom
veeceey:fix/issue-1826-punycode-deprecation

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 13, 2026

Bumps whatwg-url from ^5.0.0 to ^7.0.0 to fix the punycode deprecation warning (DEP0040) that shows up on Node.js 21+.

The root cause is that [email protected] depends on tr46@~0.0.3, which uses Node's built-in punycode module — deprecated since Node 21. Updating to whatwg-url@7 pulls in tr46@^1.0.1, which depends on the userland punycode npm package instead, so the warning goes away.

I went with v7 rather than a higher version because it has no engines restriction, keeping backward compat with older Node versions that 2.x still supports. The only API node-fetch uses from whatwg-url is the URL constructor (as a polyfill fallback), which is fully compatible across versions.

Verified locally:

  • All existing tests pass (same results as unmodified 2.x — the two pre-existing failures on Node 22 are from url.parse() deprecation, unrelated)
  • node --throw-deprecation no longer throws for punycode
  • IDN/punycode encoding still works correctly (e.g. münchen.de -> xn--mnchen-3ya.de)

Fixes #1826
Fixes #1797

[email protected] depends on tr46@~0.0.3 which uses Node's built-in
punycode module, triggering DEP0040 deprecation warnings on Node 21+.

[email protected]+ depends on tr46@^1.0.1 which uses the userland
punycode npm package instead, avoiding the deprecation warning.

This is the most conservative version bump that fixes the issue while
maintaining backward compatibility with older Node.js versions (no
engine restriction in whatwg-url@7).

Fixes node-fetch#1826
Fixes node-fetch#1797
@veeceey
Copy link
Author

veeceey commented Feb 19, 2026

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

@TimShilov
Copy link

I'm not sure this is enough.

I have also just encountered this deprecation warning, but it is not coming from tr64 but from whatwg-url itself:

[16:14:01]  ERROR  Node warning: The punycode module is deprecated. Please use a userland alternative instead. The punycode module is deprecated. Please use a userland alternative instead.

    at node:punycode:7:10
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10)
    at loadBuiltinModule (node:internal/modules/helpers:125:7)
    at loadBuiltinWithHooks (node:internal/modules/cjs/loader:1195:15)
    at Module._load (node:internal/modules/cjs/loader:1285:48)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
    at Module.require (node:internal/modules/cjs/loader:1548:12)
    at require (node:internal/modules/helpers:152:16)
    at Object.<anonymous> (/Users/tim.shilov/p/node_modules/.pnpm/[email protected]/node_modules/whatwg-url/lib/url-state-machine.js:2:18)

I believe that at least version [email protected] is required, as that's the one where punycode usage was actually removed.

However, even 9.0.0 is probably not enough as it still depends on [email protected], but the punycode deprecation was fixed only in [email protected].

whatwg-url v7.x and v8.x directly require("punycode") from Node's
built-in module, which is deprecated since Node 16 and removed in v22.
v9.0.0 is the first release that fully removes this direct usage;
it delegates all punycode work to tr46 which depends on the userland
punycode npm package instead.
@veeceey
Copy link
Author

veeceey commented Feb 27, 2026

You're right, @TimShilov. Thanks for the detailed report.

The original change bumping to ^7.0.0 was insufficient. I've investigated the whatwg-url release history and found the root cause:

  • whatwg-url v5.x through v8.x all contain const punycode = require("punycode") directly in lib/url-state-machine.js / dist/url-state-machine.js, calling into Node's deprecated built-in module. None of those versions list punycode as an npm dependency, so they rely on Node's built-in.
  • [email protected] is the first release that fully removes this direct require("punycode") call. From v9 onward, all punycode work is delegated to tr46, which depends on the userland punycode npm package (v2.x) instead.

I've updated the range to ^9.0.0 in the latest commit. Note that [email protected] requires Node >=12, but that is consistent with where node-fetch's active user base is today.

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.

2 participants