-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Ability to suppress warnings by type (or just experimental warnings) #30810
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
Comments
Adds a command line option to supress experimental warnings. Currently this cannot be accomplished without supressing all warnings (by using the --no-warnings option). However, once this option is enabled, a user can miss out on essential warnings as this supresses all warnings. This commit adds the --no-experimental-warnings command line option to allow users to ignore warnings they will expect while still being able to monitor unexpected warnings. Fixes: nodejs#30810
|
@JoshMcCullough Yes the code works, note that the parameters for my replacement function are |
I was suggesting that your |
https://nodejs.org/dist/latest/docs/api/process.html#process_process_emitwarning_warning_options shows that process.emitWarning can also take an options object as the second argument. I don't think the ESM warning uses that style call but I still check for it as I want my code to continue working if the ESM warning switches to the options object. |
In the absence of something like the feature proposed here: nodejs/node#30810 Let's just take the heavy-handed approach of suppressing all warnings unless `--debug` is in effect. Keeps ugly: (node:19198) ExperimentalWarning: The ESM module loader is experimental. out of the console. Will rip this all out once it moves out of experimental status.
Introduce an option `--suppress-warnings` to silence experimental and deprecation warnings for specified features Fixes: nodejs#30810 Co-Authored-By: Cody Deckard <[email protected]>
this would have been cool, especially for those of us using experimental loader (which I presume will be experimental for quite some time?) |
The proposed hack with It works when I trigger My cmd arguments are |
@ChuanyuanLiu which version of Node are you using? Overriding UPD I found a patch that works both in Node 16 and 18 🎉 |
A recent change (#42314) converted some of ESMLoader's experimental warning emissions from using |
I want a solution which is simple yet easy to port to any project using fetch. So I shorten it into just 2 lines of code in my entry script.
|
That Maybe you could share a GitHub repo or NPM package complete with unit and integration tests. It would be nice if your solution also type-checked properly. I'm sure folks would be happy to review your code. |
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
I add a shebang like this to make the bin script working without showing the warnings. And it works for windows too.
|
On my Linux box, this needs to be:
The I saw somebody do an executable Dockerfile with The other thing you gotta keep in mind when starting a script with a shebang is that it becomes unimportable in |
@egasimus Yes, I also find this option is necessary when running on linux. see also liudonghua123/node-sea@04fa6ec. |
@liudonghua123 Yes. Does it still work on Mac and Windows when you add that option? |
It works on windows and linux, I have not tested on macos yet. |
Also works on macOS! I just tested it. |
Hi, does anyone know a way of doing this with just environment variables? In my case I have no access to the args of the node binary. |
|
According to nodejs/node#30810 We need to use `#!/usr/bin/env -S node --no-warnings=ExperimentalWarning` on Linux. Otherwise it hangs. This flag also works on other OS environments.
Can node process set its own process.env.NODE_OPTIONS ? Or will that not have effect after startup |
Is your feature request related to a problem? Please describe.
I'd like to suppress experimental warnings while still seeing any other errors. In particular when I am using native ES modules I do not want the experimental warning printed for every process, but I do want unrelated warnings to still be printed.
Describe the solution you'd like
Allow
--no-warnings
to optionally accept an option string such as--no-warnings=type1,type2
. Using--no-warnings
without any option would continue to disable all warnings. This would allow--no-warnings=ExperimentalWarning
to suppress ExperimentalWarning only.Describe alternatives you've considered
--no-experimental-warnings
or a similarly named new flag could be created. This has the drawback thatnode --no-experimental-warnings
on node.js 13.3.0 exit with an error where--no-warnings=ExperimentalWarnings
will not currently error (it causes all warnings to be ignored).In my own repo which uses ES modules I've created
suppress-experimental.cjs
which gets loaded withNODE_OPTIONS='--require=./suppress-experimental.cjs'
:Obviously patching node.js internals like this is undesirable but it accomplishes my goal.
The text was updated successfully, but these errors were encountered: