Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeprecationWarning: The `punycode` module is deprecated when using a database with Mongoose

Why am I getting the following warning?

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)

my OS is Ubuntu 22.04.

The error occurred when I try 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.

As I understand it, the punycode is deprecated, and I need to use userland as an alternative. But I don't know how to use that. I installed the userland module but nothing happens.

like image 367
Margin wings Avatar asked Sep 03 '25 13:09

Margin wings


1 Answers

Quick Solution for the Punycode Deprecation Warning

If the Node.js version is not critical for your use case, you can resolve the issue with the following steps:

Option 1: Use an earlier Node.js version

Punycode is deprecated in Node.js version 21 and later. To avoid the warning, you can install and use Node.js version 20.5.1 with NVM:

nvm install 20.5.1
nvm use 20.5.1

Option 2: Suppress the deprecation warning

If changing the Node.js version isn’t feasible, you can suppress the deprecation warnings by setting the following environment variable:

export NODE_OPTIONS="--no-deprecation"
like image 71
Mike Yang Avatar answered Sep 05 '25 17:09

Mike Yang