Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Salesforce CLI outputs "DeprecationWarning: The punycode module is deprecated." after every sf command. #2535

Open
catalandres opened this issue Oct 24, 2023 · 30 comments
Labels
area:jsforce bug Issue or pull request that identifies or fixes a bug validated Version information for this issue has been validated

Comments

@catalandres
Copy link

Summary

Running the sf CLI under node v21.0.0 throws out the following warning:

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

Steps To Reproduce

  • Upgrade node to v21.
  • Run any sf command. For example, sf --version.

Expected result

@salesforce/cli/2.13.9 darwin-arm64 node-v21.0.0

Actual result

(node:83092) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
@salesforce/cli/2.13.9 darwin-arm64 node-v21.0.0

System Information

{
  "architecture": "darwin-arm64",
  "cliVersion": "@salesforce/cli/2.13.9",
  "nodeVersion": "node-v21.0.0",
  "osVersion": "Darwin 23.0.0",
  "rootPath": "/opt/homebrew/lib/node_modules/@salesforce/cli",
  "shell": "zsh",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 2.3.9 (core)",
    "@oclif/plugin-commands 2.2.28 (core)",
    "@oclif/plugin-help 5.2.20 (core)",
    "@oclif/plugin-not-found 2.4.3 (core)",
    "@oclif/plugin-plugins 3.9.1 (core)",
    "@oclif/plugin-search 0.0.23 (core)",
    "@oclif/plugin-update 3.2.4 (core)",
    "@oclif/plugin-version 2.0.1 (core)",
    "@oclif/plugin-warn-if-update-available 2.1.1 (core)",
    "@oclif/plugin-which 2.2.34 (core)",
    "@salesforce/cli 2.13.9 (core)",
    "apex 2.3.19 (core)",
    "auth 2.8.20 (core)",
    "data 2.5.16 (core)",
    "deploy-retrieve 1.19.0 (core)",
    "dev 1.2.0 (user)",
    "info 2.6.49 (core)",
    "limits 2.3.38 (core)",
    "login 1.2.35 (core)",
    "marketplace 0.3.0 (core)",
    "org 2.10.12 (core)",
    "schema 2.3.29 (core)",
    "settings 1.4.33 (core)",
    "sobject 0.2.11 (core)",
    "source 2.10.40 (core)",
    "telemetry 2.3.6 (core)",
    "templates 55.5.14 (core)",
    "trust 2.6.18 (core)",
    "user 2.3.36 (core)"
  ]
}

Additional information

Apparently, punycode has been deprecated starting with node v21.

@catalandres catalandres added the investigating We're actively investigating this issue label Oct 24, 2023
@github-actions
Copy link

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

@github-actions github-actions bot added the validated Version information for this issue has been validated label Oct 24, 2023
@cristiand391 cristiand391 added bug Issue or pull request that identifies or fixes a bug and removed investigating We're actively investigating this issue labels Oct 24, 2023
@git2gus
Copy link

git2gus bot commented Oct 24, 2023

This issue has been linked to a new work item: W-14355613

@cristiand391
Copy link
Member

Hi @catalandres , we noticed this too a few days ago and tracked it down to 1 dep (whatwg-url):

➜  cli git:(9600617) NODE_OPTIONS='--trace-deprecation' sf config list
(node:67085) [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:102:7)
    at Module._load (node:internal/modules/cjs/loader:995:17)
    at Module.require (node:internal/modules/cjs/loader:1229:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/Users/cdominguez/.nvm/versions/node/v21.0.0/lib/node_modules/@salesforce/cli/node_modules/whatwg-url/lib/url-state
-machine.js:2:18)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)

whatwg-url is used by node-fetch v2 (jsforce) and @octokit/request(templates/plugin-templates - via yeoman deps).

for node-fetch there's a PR to bump it but were waiting to get the jsforce test pipeline stable (node-fetch v3 is an ESM package, we'll have to do more changes probably): jsforce/jsforce#1356

for octokit deps we shared this with the IDEx team (they own templates), no ETA yet.

If you are using sf on node v21 and trying to parse CLI output, make sure to only parse stdout (node warning is sent to stderr).

@chechuan
Copy link

This question is bothering me. I searched the internet but couldn't find an answer

@RoboProgrammer69
Copy link

downgrade node to 20.9.0 version

@AmrMohamed001
Copy link

downgrade node to 20.9.0 version

this work👌

@cristiand391
Copy link
Member

@RoboProgrammer69 @AmrMohamed001 are you all downgrading to node 20 because of the warning or are you getting an install error on v21?

@AmrMohamed001
Copy link

@RoboProgrammer69 @AmrMohamed001 are you all downgrading to node 20 because of the warning or are you getting an install error on v21?

Yes as this is unknown warning

@maion308
Copy link

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

@cristiand391
Copy link
Member

@maion308 this warning doesn't break any CLI functionality (if you are parsing CLI output you should always use stdout), why are you swapping the core punycode module?

@wcleveland
Copy link

@cristiand391 He's following the instructions provided by the readme for punycode.

⚠️ Note that userland modules don't hide core modules. For example, require('punycode') still imports the deprecated core module even if you executed npm install punycode. Use require('punycode/') to import userland modules rather than core modules.

@cristiand391
Copy link
Member

please note that this is repo is for Salesforce CLI issues, I think some people is getting here when googling for that warning.

@BianorAraujo
Copy link

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

works like a charm!
thanks

@franciscoxaa
Copy link

I have de issue
node v21.1.0
pnpm 8.10.5
biome ^0.3.3

I run:

`$ biome format --write ./src

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

Does anyone know how to solve it?

@gurleen-codes
Copy link

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

works like a charm! thanks

How did you access the directory tr46? all I see in node_modules is the 'punnycode' folder and the package-lock JSON file.

@catalandres catalandres changed the title DeprecationWarning: The punycode module is deprecated. The Salesforce CLI outputs "DeprecationWarning: The punycode module is deprecated." after every sf command. Nov 16, 2023
@catalandres
Copy link
Author

@cristiand391 Sadly, this thread is getting polluted with comments that are relevant to other projects. I have renamed the issue to make it clear that this is relevant to our tool.

For what it's worth, there is a reasonable temporary solution to this — use nvm to ensure that the default global environment is v20, not v21. And once all the dependencies for @salesforce/cli are v21-compliant this will be a non-issue.

@forcedotcom forcedotcom deleted a comment from BianorAraujo Nov 16, 2023
@cristiand391
Copy link
Member

Locking this issue for a bit, if this warning is affecting scripts parsing Salesforce CLI output see this comment:
#2535 (comment)

@forcedotcom forcedotcom locked as off-topic and limited conversation to collaborators Nov 16, 2023
@forcedotcom forcedotcom unlocked this conversation Jul 4, 2024
@akalatksy
Copy link

akalatksy commented Oct 12, 2024

downgrade node to 20.9.0 version

Or use --disable-warning DEP0040.
Probably not a solution to the punycode deprecation problem, but an alternative option to acheive the exact Expected result from OP problem (node-v21.0.0 without the warning).

The --disable-warning flag was added in node v21.3.0) and allows suppression of specific warnings.

PS. You can set this flag using the NODE_OPTIONS='--disable-warning DEP0040' environment varable.
While there may be a better or more correct way to configure this flag (I'd appreciate all the suggestions), but it worked perfectly for my needs: to remove this warning from the CI/CD logs.

@tggagne
Copy link

tggagne commented Oct 23, 2024

So is there an official fix coming for this or is there nothing sf cli can do here? At some point if we all stop upgrading node at v20.5.x, won't vscode or sf eventually require an upgrade?

@cristiand391
Copy link
Member

@tggagne yes, we have 2 possible workarounds for this before node v22 gets promoted to LTS.

@nvuillam
Copy link

The warning is back :'(

@catalandres
Copy link
Author

Does this have to do with having included Node v22 LTS in the binary packages starting this week?

@nvuillam
Copy link

Does this have to do with having included Node v22 LTS in the binary packages starting this week?

Yes ^^

@catmac42
Copy link

I'm seeing this warning too, and it's preventing me from authorizing my org, so I can't retrieve or push any code. I have a fresh Windows install on my work laptop as of 2 weeks ago, but only just got admin permissions so I can install what I need for my developer environment.

I'm running the following versions:
VS Code - 1.95.3
SF CLI - 2.66.7 win32-x64
VSCode CLI Integration Extension - v62.5.1

Do we know when a fix for this will be in place @cristiand391? I have run through the various fixes suggested in this thread and on #3111 to no avail.

@nvuillam
Copy link

@catmac42 as workaround, you can downgrade NodeJS to 20.x :)

@catmac42
Copy link

I'm not a regular NodeJS user so not extremely knowledgeable about this, but I did try downgrading to NodeJS 20.18.0 (just by uninstalling and reinstalling Node to the right version), but the SF CLI seems to think that it's still on v22 when I run sf --version in the terminal -
image

Any advice welcome! NB I'm a Windows user so standard nvm isn't an option, and I'm unsure whether there's a "safe" option for Windows.

@nvuillam
Copy link

@catmac42 if you installed SF Cli using windows installer, uninstall it, then reinstall it again with npm install @salesforce/cli -g :)

@Krishnamurthy-sfdx
Copy link

Krishnamurthy-sfdx commented Nov 21, 2024

@nvuillam For mac, is there a way to get rid of it? or downgrade?. I started experiencing this issue after I wanted to try out the sfdx-hardis extension.

@catalandres
Copy link
Author

catalandres commented Nov 21, 2024 via email

@nvuillam
Copy link

@nvuillam For mac, is there a way to get rid of it? or downgrade?. I started experiencing this issue after I wanted to try out the sfdx-hardis extension.

Like @catalandres says 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:jsforce bug Issue or pull request that identifies or fixes a bug validated Version information for this issue has been validated
Projects
None yet
Development

No branches or pull requests