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

Ability to suppress warnings by type #47478

Closed
karlhorky opened this issue Apr 8, 2023 · 3 comments · Fixed by #50661
Closed

Ability to suppress warnings by type #47478

karlhorky opened this issue Apr 8, 2023 · 3 comments · Fixed by #50661
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Apr 8, 2023

This issue is a followup on #30810 by @coreyfarrell, but specifically only for warnings of a specific type / topic

What is the problem this feature will solve?

After a team has thoughtfully considered using experimental features of their Node.js version (eg. fetch) and decided the tradeoffs are acceptable for their project, showing the warnings every time their script runs is often not necessary and can be noisy and confusing, making debugging more arduous.

Such a warning, for fetch in Node.js v18.12.1 (I'm aware that newer versions do not have this warning anymore):

$ node -v
v18.12.1
$ echo "fetch('https://example.com')" > x.mjs
$ node x.mjs
(node:329) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
$ node x.mjs
(node:1282) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Replit demo: https://replit.com/@karlhorky/Nodejs-18121-fetch-experimental-warning

What is the feature you are proposing to solve the problem?

It would be great to be able to disable warnings by:

1. Specific warning code(s)

# Disabling a single warning code
node --no-warnings=WARN_FETCH_EXPERIMENTAL

# Disabling multiple warning codes
node --no-warnings=WARN_FETCH_EXPERIMENTAL,WARN_JSON_IMPORT_EXPERIMENTAL

2. Topic(s)

# Disabling a single warning topic
node --no-warnings=WARN_TOPIC_MODULES

# Disabling a single warning topic
node --no-warnings=WARN_TOPIC_EXPERIMENTAL

# Disabling multiple warning topics
node --no-warnings=WARN_TOPIC_MODULES,WARN_TOPIC_FETCH

Prior art / similar APIs

What alternatives have you considered?

Workaround

To suppress the experimental fetch warnings like ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time, this is what we used:

package.json

{
  "scripts": {
    "start": "node --require ./suppress-experimental-fetch-warnings.js index.js"
  }
}

suppress-experimental-fetch-warnings.js

// Suppress Node.js warning about experimental fetch API
// Ref: https://github.com/nodejs/node/issues/30810#issuecomment-1383184769
const originalEmit = process.emit;
process.emit = function (event, error) {
  if (
    event === 'warning' &&
    error.name === 'ExperimentalWarning' &&
    error.message.includes('The Fetch API is an experimental feature.')
  ) {
    return false;
  }

  return originalEmit.apply(process, arguments);
};

An alternative would be to add official Node.js documentation (in a "recipes" or "examples" section) with idiomatic suppression example code + configuration that users could copy into their projects for every warning type.

@SimenB
Copy link
Member

SimenB commented Apr 8, 2023

+1 to this. Since the vm ESM APIs remain experimental, it'd be great to suppress its warnings when running Jest with native ESM.

https://jestjs.io/docs/ecmascript-modules

@axkibe
Copy link
Contributor

axkibe commented Apr 10, 2023

Honestly if the command line explicitly turns on an experimental feature I don't see the point of these warning at all.

@Ethan-Arrowood
Copy link
Contributor

I'm going to try to implement this feature soon. Probably will be a couple weeks because of other responsibilities, but unless someone beats me to it I'll try to get this implemented 🚀

nodejs-github-bot pushed a commit that referenced this issue Nov 21, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
targos pushed a commit that referenced this issue Nov 23, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
martenrichter pushed a commit to martenrichter/node that referenced this issue Nov 26, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: nodejs#50661
Fixes: nodejs#30810
Fixes: nodejs#47478
Fixes: nodejs#46862
Fixes: nodejs#40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
lucshi pushed a commit to lucshi/node that referenced this issue Nov 27, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: nodejs#50661
Fixes: nodejs#30810
Fixes: nodejs#47478
Fixes: nodejs#46862
Fixes: nodejs#40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
RafaelGSS pushed a commit that referenced this issue Nov 29, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
RafaelGSS pushed a commit that referenced this issue Nov 30, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
UlisesGascon pushed a commit that referenced this issue Dec 11, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
UlisesGascon pushed a commit that referenced this issue Dec 15, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
UlisesGascon pushed a commit that referenced this issue Dec 19, 2023
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
PR-URL: #50661
Fixes: #30810
Fixes: #47478
Fixes: #46862
Fixes: #40940
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
@RedYetiDev RedYetiDev moved this from Awaiting Triage to Done in Node.js feature requests Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants