DeprecationWarning: The `punycode` module is deprecated

9.9k Views Asked by At

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

This is the issue. my OS was ubuntu 22.04. The problem cames when i am trying to use my database with mongoose. The punycode can see somewhere in my package-lock.json file. I didn't use it myself , it's coming with node.

My node version is v21.0.0 , i downgraded it into v20.9.0 then v18.18.0 still the warning is there. I installed userland module but nothing happens.

The problem i understand was the punycode is deprecated and need to use userland alternative punycode.js . But i didn't know how to make it possible.

4

There are 4 best solutions below

3
On

This is how I solved this Deprecation Warning:

Here’s a workaround that might help:

  1. Go to your node_modules directory.

  2. Find the tr46 directory.

  3. Open the index.js file in the tr46 directory.

  4. Replace current require line with this line:

    const punycode = require('punycode/');

But if you re-install npm packages, or update them, this correction will be lost. However, the Warning disappeared.

PS: Just in case, I use node v21.5.0

0
On

this problem happen because punycode is deprecated in node version 21 and above... downgrade to node version 20

1
On

had the same problem, i looked for punycode and found it in package-lock.json the reason was i was using new version of Node.js v21.5.0, which explains the deprecation warning for punycode. i updated uri-js and that solved the problem npm install [email protected]

solved the problem

0
On

Punycode is deprecated in node version 21
Solution:NVM install and use node version 20.5.1

nvm install 20.5.1
nvm use 20.5.1