How to fix DeprecationWarning: punycode is deprecated #66289
Replies: 13 comments 21 replies
-
In this case the issue is that, Node itself is removing this module from its API. Any library that relied on it, that you, transitively use, is triggering this warning. Best you can do is, figure out which one, and go try to help their developers replace punycode with a different module. I don't think it comes from Next.js itself, but I can be wrong of course. I know they use it in some tests, but those are not shipped in the next package, and the next package itself uses an npm package instead. |
Beta Was this translation helpful? Give feedback.
-
What about the README in the punycode that says that you should be using const punycode = require('punycode/'); |
Beta Was this translation helpful? Give feedback.
-
just downgrade your version of node to LTS v20.17.0 and it will fix your issue |
Beta Was this translation helpful? Give feedback.
-
Hello, I spent some time on this issue and it appears that it is related to the packages that have a dependency on 'punycode' and the syntax they used to include punycode, as was mentioned. If these require statements are fixed and patched the problem should go away. Patching a few packages is not a huge deal, however, if your project contains many packages that depend on punycode then in my opinion it is probably best to just put up with the warning. The following command should show which packages need to be patched and at which offending files. It recursively searches the ./node_modules tree to find punycode require statements for both variations: require("punycode") & require('punycode'). Note that it will exclude all './file' directives which are just duplicates created by grep. It will also exclude require statement that appear in README files. When there are no offending entries, then the command below should return nothing.
On some distro's you might need to give the query a target, e.g. '.' (if in node_modules) or 'node_modules/' (if in the root folder of your project): Example: In my project the command returned the following, suggesting 3 offending modules:
Per the punycode documentation I updated the require statements in these files as shown below:
Following these changes the deprecation error went away. However, if you follow this procedure and continue to see the issue, then it might be the case that another variation of the require statement is present in your project and not caught by the grep command. Thus, it might be necessary to update the search command accordingly. Once you have made the changes and confirmed that the issue is addressed, patch the modules in order to ensure that on subsequent installs the changes will be applied retroactively by the patch-package postinstall script. This postinstall script will also let you know when it is time to delete a patch (presuming that the owners of these packages apply the changes in future versions). Install patch-package: Update package.json:
Create the patches:
Example: Based on the modules impacting my project, I ran the following:
Start the project (no errors/warnings):
In order to test the patches to ensure that they are retroactively applied on new installations:
Note: For ios make sure you: Hope it helps :) |
Beta Was this translation helpful? Give feedback.
-
I was just battling this deprecation error, and I decided to switch through node versions.
I still need a proper solution to this issue, no solution works yet |
Beta Was this translation helpful? Give feedback.
-
I added a .nvmrc file with content: |
Beta Was this translation helpful? Give feedback.
-
Hi! |
Beta Was this translation helpful? Give feedback.
-
@ikarkam76 This was the exact situation that I was facing, brew had installed node a dependency somehow and my path for node was wrong. Thank you! |
Beta Was this translation helpful? Give feedback.
-
I had to use this command line I am using next: "15.0.3" and Node 22. |
Beta Was this translation helpful? Give feedback.
-
After upgrading Node.js from v20 to v22.11.0, I also got this warning in my project. Traced it down to [email protected]
I'm using Next.js 14.2.18 (turbo), and as far as I recall eslint-config-next (I use 14.2.18) doesn't work with eslint 9.x yet? Unsure if I am willing to upgrade the project to Next.js 15 yet... So not sure how to solve the warning, except downgrading Node.js back to v20 maybe? |
Beta Was this translation helpful? Give feedback.
-
Oof untraceable |
Beta Was this translation helpful? Give feedback.
-
Maybe this work for you |
Beta Was this translation helpful? Give feedback.
-
if you face this waning with openai-node, it prevents with v5.0.0-alpha0 |
Beta Was this translation helpful? Give feedback.
-
Summary
When I run pnpm run dev on vscode on a freshly created next project, I get this
▲ Next.js 14.2.3
✓ Starting...
✓ Ready in 3.2s
(node:14572) [DEP0040] DeprecationWarning: The
punycode
module is deprecated. Please use a userland alternative instead.(Use
node --trace-deprecation ...
to show where the warning was created)○ Compiling / ...
(node:14572) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
✓ Compiled / in 2.1s (532 modules)
I don't know how this warning is triggered. I used node --trace-deprecation ..., but I get this error
victornasar@My-MacBook-Pro project1 % node --trace-deprecation ...
Node.js v22.2.0
I use homebrew to install node and pnpm.
npm: '10.7.0',
node: '22.2.0',
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions