yarnpkg/yarn

"[DEP0040] The `punycode` module is deprecated" with Node.js 21.x

MikeMcC399 opened this issue Β· 38 comments

Many Yarn Classic commands including

yarn info
yarn add
yarn install

provoke a deprecation warning under Node.js current version 21.x.

[DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.

Yarn version

Yarn Classic v1.22.19

Steps to reproduce

For example, with Node.js 21.1.0 installed, execute:

npm install yarn -g
yarn info yarn description

shows

$ npm install yarn -g
changed 1 package in 909ms
$ yarn info yarn description
yarn info v1.22.19
(node:2136) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
πŸ“¦πŸˆ Fast, reliable, and secure dependency management.
Done in 0.23s.

Further debug information is output by:

NODE_OPTIONS='--trace-deprecation' yarn info yarn description

Comments

The History section of DEP0040 in the Node.js documentation shows that Node.js punycode has been deprecated since Node.js v7.0.0 in Oct 2016 and, starting with Node.js v21.0.0, this has been changed to a runtime deprecation (see nodejs/node#47202). The runtime deprecation is what has caused it to now become visible.

Node.js v21.0.0 was released on Oct 17, 2023 as the first release of the 21.x major version, so the issue is quite new. Because Yarn Classic v1 is frozen I don't expect this deprecation to be fixed. I'm just sharing because I was confused the first time I saw it and I mistakenly thought that the package I was installing with yarn add was causing the message, not Yarn Classic itself.

(For completeness I mention https://nodejs.org/dist/latest-v21.x/docs/api/punycode.html in combination with the comment in the https://github.com/mathiasbynens/punycode.js#installation section of the userland module about how to fix.)

I'm not seeing DEP0040 shown by Yarn Modern stable 4.0.1, so migrating to Yarn Modern would be a logical mitigation for the deprecation message caused by Yarn Classic.

If anyone here who is getting this warning on windows after updating to node version 21.1.0 then you need to update the npm itself. type 'npm install -g npm@latest' in cmd and that probably fix your issue. It worked for me.

If anyone here who is getting this warning on windows after updating to node version 21.1.0 then you need to update the npm itself. type 'npm install -g npm@latest' in cmd and that probably fix your issue. It worked for me.

doesn't work on macOS

@ashfaque9426

I can't reproduce your findings. On Windows 11 23H2

$ node -v
v21.1.0
$ npm -v
10.2.3
$ yarn -v
1.22.19
$ yarn info yarn description
yarn info v1.22.19
(node:26048) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
πŸ“¦πŸˆ Fast, reliable, and secure dependency management.
Done in 0.27s.

@ashfaque9426

I can't reproduce your findings. On Windows 11 23H2

$ node -v
v21.1.0
$ npm -v
10.2.3
$ yarn -v
1.22.19
$ yarn info yarn description
yarn info v1.22.19
(node:26048) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
πŸ“¦πŸˆ Fast, reliable, and secure dependency management.
Done in 0.27s.

Sir, I am working on windows 10 22H2 I thought It would work for windows 11 as well. I apologise. I would like to mention while updating the node I completely uninstalled it from the registry file as well and then updated via the node windows installer from node's official website. You can try this as well it may work. I have uninstalled node using IOBIT uninstaller and the pro version of it automatically removes uninstallation leftovers from the registry as well.

@ashfaque9426

Could you post the output of

node -v
yarn -v
yarn info yarn description

On my Windows 10 22H2 system the problem is also present. I would not expect anything different because Yarn Classic uses dependencies, such as tr46@1.0.1, which use the built-in version of punycode from Node.js and not the userland version.

@ashfaque9426

Could you post the output of

node -v
yarn -v
yarn info yarn description

On my Windows 10 22H2 system the problem is also present. I would not expect anything different because Yarn Classic uses dependencies, such as tr46@1.0.1, which use the built-in version of punycode from Node.js and not the userland version.

Here is my output sir seems like using the latest version same as you.

Microsoft Windows [Version 10.0.19045.3570]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Ashfaq Sylvi>npm --version
10.2.3

C:\Users\Ashfaq Sylvi>yarn --version
1.22.19

C:\Users\Ashfaq Sylvi>yarn info yarn description
yarn info v1.22.19
πŸ“¦πŸˆ Fast, reliable, and secure dependency management.
Done in 0.20s.

One thing I forgot to mention, I have used cmd for those commands

@ashfaque9426

Please post the output of

node -v

I can only see the version of npm in your post, not of node.

I'm also getting this on latest MacOS (sonoma) in Terminal. Admitted n00b to all this, but here is the info asked for just above in case it helps:

% node -v
v21.1.0

% yarn -v
1.22.19

% yarn info yarn description
yarn info v1.22.19
(node:11987) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

I'll make a patch to fix this (but indeed, newer releases don't have this problem and various others, so I suggest try to migrate and letting us know on Discord if you hit a blocker; at the time of this post the latest release is 4.0.1).

Hi @arcanis

I'm involved with the GitHub JavaScript action cypress-io/github-action which supports both Yarn Classic and Yarn Modern, so I'm happy that there will be a patch for Yarn Classic.

I fully understand the general advice to migrate though.

Many thanks!

I'm also getting this on latest MacOS (sonoma) in Terminal. Admitted n00b to all this, but here is the info asked for just above in case it helps:

% node -v
v21.1.0

% yarn -v
1.22.19

% yarn info yarn description
yarn info v1.22.19
(node:11987) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

@erikspears Try to downgrade node to 20.9.0 version. I had similar problem and this help me

Fixed in #9009

@merceyz

Yes, we're working on that. We don't release 1.x often, so the CI is unfortunately a little unstable - it may take us a day or two to propagate all the archives.

@arcanis

Thanks for fixing the deprecation issue and good luck in resolving the publication issues as well!

@arcanis

I am still seeing this issue with
Node.js: v21.2.0
Yarn: v1.22.21

$ yarn info yarn description
yarn info v1.22.21
(node:18924) [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 (C:\Users\mikem\AppData\Roaming\npm\node_modules\yarn\lib\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\mikem\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:56536:18)
    at __webpack_require__ (C:\Users\mikem\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:22:30)
    at Object.<anonymous> (C:\Users\mikem\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:71815:18)
πŸ“¦πŸˆ Fast, reliable, and secure dependency management.
Done in 0.46s.
  • re-submitted as #9013 for clarity

I hit this today on Mac OS 14.1.1 (23B81). Thanks for planning the fix .

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

still present in windows Node 21.3.0
http://puu.sh/JVJG7/3f31ba597c.png

still present in windows Node version 21.2.0
image

Yarn has officially jumped the shark

Original : bitwarden/clients#6689 (comment)

solution that worked for me:
npm install punycode --save

and then in node_modules go to the directory tr46 > index.js

// Replace this:
const punycode = require('punycode');
// With this:
const punycode = require('punycode/');

basically just add a trailing forward slash

Reverting to node version 20.5.1 worked for me. (Incase you're frustrated and looking for a quick solution to get rid of the warning)

Step 1. Install NVM

Windows

winget install CoreyButler.NVMforWindows

Linux

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Step 2. NVM install and use node version 20.5.1

nvm install 20.5.1
nvm use 20.5.1

@xthukuh

The LTS version according to https://nodejs.org/en is 20.10.0. You might want to consider using this one.

@xthukuh

The LTS version according to https://nodejs.org/en is 20.10.0. You might want to consider using this one.

Thank you. I was rushing for a fix. I'll consider this.

still got same error

@handidev

still got same error

  • You can follow #9013 for the open issue.

still got same error

just downgrade to 20.10.0
it is depreciated in 21.5.0

In cmd

nvm install 20.10.0

nvm use 20.10.0

Done

thanks minav that ruined my proj

I don't even use punycode in my project and this somehow was installed by pnpm.

serv@hey node-back % sudo pnpm run dev         

> hz@1.0.0 dev /Users/hey/Documents/Code/node-back
> npx nodemon ./main.ts

[nodemon] 3.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node ./main.ts`
check env mongodb+srv://£££££££££££:$$$$$$$$@cluster-0.qevpnkh.mongodb.net/?retryWrites=true&w=majority

mongodb+srv://ghyvl:nXsvoJ4kiVtrKp6T@cluster-0.qevpnkh.mongodb.net/?retryWrites=true&w=majority
(node:38118) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Server is on port 3000
^C ELIFECYCLE  Command failed.

I upgraded Node to 21.5 and now I'm also getting this issue. Any issue if I ignore this warning?

@crealityeducation

I upgraded Node to 21.5 and now I'm also getting this issue. Any issue if I ignore this warning?

It's only a warning that it could stop working in some future Node.js version > 21.x, as yet undefined, so you are free to ignore the warning. The deprecation is only saying "please plan ahead".

Hi Mike, Thanks for confirming. I'll keep checking this space for upgrade. Have a good day.

Original : bitwarden/clients#6689 (comment)

solution that worked for me: npm install punycode --save

and then in node_modules go to the directory tr46 > index.js

// Replace this: const punycode = require('punycode'); // With this: const punycode = require('punycode/');

basically just add a trailing forward slash

Thanks for this. Good to know there is a workaround.
But knowing it's an insignificant issue, which will go away with future releases, seems I'll just manage it for now.

My specific error response by the way is stated below. I currently get it on every single node.js project I create.

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

Remove node.js and install node.js LTS version. It will fix the issue.
https://nodejs.org/en/download/

v21.5.0 still has this message

@MariuzM

v21.5.0 still has this message

  • You can follow the open issue #9013