Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js 21: "[DEP0040] DeprecationWarning: The punycode module is deprecated." #789

Closed
MikeMcC399 opened this issue Oct 21, 2023 · 4 comments

Comments

@MikeMcC399
Copy link

MikeMcC399 commented Oct 21, 2023

Description

Running serve under Node.js 21.x version causes the following deprecation notice to be displayed:

(node:24848) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)

The message is also shown in response to serve -v.

Node.js v21.0.0 (Current) was released on Oct 17, 2023.

Steps to reproduce

npm install serve -g
export NODE_OPTIONS='--trace-deprecation'
serve -v

shows

added 89 packages in 8s

24 packages are looking for funding
  run `npm fund` for details
(node:4213) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:392:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:328:10)
    at loadBuiltinModule (node:internal/modules/helpers:101:7)
    at Module._load (node:internal/modules/cjs/loader:1001:17)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/home/mike/n/lib/node_modules/serve/node_modules/fast-url-parser/src/urlparser.js:401:16)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
14.2.1

https://nodejs.org/dist/latest-v21.x/docs/api/deprecations.html#DEP0040 lists the deprecation and shows that a runtime deprecation was added to Node.js v21.0.0 (see nodejs/node#47202).

Library version

First reported on version: 14.2.1
Still reproducible with version: 14.2.2

Node version

v21.0.0
v21.7.3

Related issues

@MikeMcC399
Copy link
Author

MikeMcC399 commented Nov 21, 2023

The serve dependency fast-url-parser can be patched as a temporary measure. Starting with the following:

mkdir serve-test
cd serve-test
npm init -y
npm install serve
export NODE_OPTIONS='--trace-deprecation'
npx serve -v

Workaround

Use npm module patch-package

npm install patch-package

add script to package.json

"postinstall": "patch-package"

Edit node_modules\fast-url-parser\src\urlparser.js
Line 401

Change

var punycode = require("punycode");

to

var punycode = require("punycode/");

then execute

npx patch-package fast-url-parser

To verify, execute again:

npx serve -v

There should be no deprecation message, even when running under Node.js 21.x.

For package managers other than npm, see README of patch-package.

@tik9
Copy link

tik9 commented Dec 24, 2023

Should I execute the code on top mkdir serve-test.. and then execute the workaround?

@MikeMcC399
Copy link
Author

@tik9

Should I execute the code on top mkdir serve-test.. and then execute the workaround?

You would replace serve-test with the name of your existing repository. Sorry if that was not clear. I just used the name serve-test to demonstrate the principal of patching. You wouldn't normally be creating a new directory if you already have a repository that you are going to patch.

@MikeMcC399
Copy link
Author

MikeMcC399 commented Apr 25, 2024

Node.js 21 is now in maintenance and reached end-of-life on June 1, 2024.

@MikeMcC399 MikeMcC399 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
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

No branches or pull requests

2 participants