DeprecationWarning: The `punycode` module is deprecated
Asked Answered
C

6

23

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.

Countryandwestern answered 1/12, 2023 at 18:22 Comment(2)
Getting the same issue with macOS as well. Can we add a ubuntu tag and macOS tag as well? I am getting it while running a react native projectCaldwell
Same problem here with macOS. It happened when I npm installed mongoose.Overhasty
J
3

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

Jacey answered 5/2 at 14:45 Comment(3)
Did you run npm install [email protected] globally, or is this per project?Viaticum
It is not in package-lock.jsonRevenant
i installed npm install uri-js but it not solved this problem. node v22Eslinger
M
1

If you don't care much about the node version, a quick way is below:
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
Maris answered 27/3 at 6:7 Comment(2)
But I am on node 16...Revenant
downgrading node is not futureproofSuperstitious
T
0

you should run code step by step: 1- npm uninstall mongoose 2- npm i mongoose

then use promise instead of callback function. for example:

const { default: mongoose } = require("mongoose"); const DB_NAME = "mongoose-tutorial"; const DB_URL = mongodb://localhost:27017/${DB_NAME}; mongoose.set("strictQuery", false);

mongoose.connect(DB_URL).then(() => { console.log(Connected to ${DB_NAME}...)}).catch((err) => { console.log(err.message); });

Tabathatabb answered 28/6 at 0:3 Comment(0)
C
0

I am using latest version of Node(v22.4.0) and npm(v10.8.1)

I have got this 2 kinda problem

  1. (node:6852) [DEP0040] (something related to mongoose package)
  2. (node:5199) [DEP0040]
  • For the first one:
    • deleted node_modules, package-log.json, mongoose
    • reinstall them back
  • For the second one:
    • deleted node_modules, package-log.json
    • reinstall them back

--> Problem Solved !!! (Hope you guys can solve the problem 🍀🤞)

Colloid answered 6/7 at 6:36 Comment(0)
L
-1

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

Logbook answered 22/1 at 14:4 Comment(0)
M
-3

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

Memphis answered 4/1 at 9:27 Comment(4)
Avoid editing files in node_modulesGerkman
look in the package-lock.json what modules use itLogbook
In this particular case, patching a package in node_modules may be warranted, especially if the target package is a dependency of some other packages. To persist the fix, try to use patch-package.Isthmian
There is no index.js file there....Revenant

© 2022 - 2024 — McMap. All rights reserved.