It's really annoying to need to always add 2>/dev/null when I use uglify -cm because the program is really spammy with stderr:
$ browserify -r stream | uglifyjs -cm | wc -c
WARN: Dropping unused function argument name [-:46,28]
WARN: Dropping unused function argument dir [-:52,26]
WARN: Dropping unused function argument exports [-:1,445]
WARN: Dropping unused variable pos [-:1122,6]
WARN: Dropping unused function argument exports [-:1172,12]
WARN: Side effects in initialization of unused variable ZERO [-:1179,5]
WARN: Dropping unused function argument exports [-:1169,58]
WARN: Dropping unreachable code [-:1441,6]
WARN: Dropping unused function argument exports [-:1378,33]
WARN: Dropping unused function argument exports [-:1680,33]
WARN: Dropping unused function argument exports [-:1705,33]
WARN: Dropping unused function argument exports [-:1779,114]
WARN: Dropping unused function argument exports [-:1781,40]
WARN: Dropping unused function argument exports [-:1910,153]
WARN: Dropping unused function argument exports [-:1912,34]
WARN: Dropping unused function argument stream [-:1990,32]
WARN: Dropping unused variable dest [-:2519,8]
WARN: Dropping unused function argument list [-:2532,26]
WARN: Dropping unused function argument i [-:2532,23]
WARN: Dropping unused function argument n [-:2403,36]
WARN: Dropping unused function argument n [-:2776,24]
WARN: Dropping unused function argument exports [-:1955,66]
WARN: Side effects in initialization of unused variable ts [-:3006,6]
WARN: Side effects in initialization of unused variable rs [-:3086,6]
WARN: Dropping unused function argument cb [-:3044,59]
WARN: Dropping unused function argument encoding [-:3044,49]
WARN: Dropping unused function argument chunk [-:3044,42]
WARN: Dropping unused function argument n [-:3065,37]
WARN: Dropping unused function argument exports [-:2892,216]
WARN: Dropping unused function argument exports [-:3098,62]
40023
None of these errors seem useful or surprising because everything works completely fine. When a program has nothing surprising to say, it should say nothing.
With most command-line programs, the expectation is that extraneous output like this is opt-in. There is already a -v flag even! I propose not writing these messages to stderr unless -v is given.
@substack: Each of those warnings tells you about an unsafe transformation that uglifyjs is making, which may change your program's behaviour. I'd call each of them surprising. Get rid of your unused variables and function arguments, and uglifyjs will be silent.
Or send warnings=false to the compressor, i.e.:
uglifyjs files... -m -c warnings=false
huh, your response is baffling. Most application are mostly based on code from 3rd parties. How would you clean code before a preprocessor step without a preprocessor step.
Uglify is an obvious choice to strip function arguments.
Will have to disable that feature to silence the warning.
:+1: It is pretty annoying having to type out this (undocumented) CLI flag to hide warnings.
Often you do not control 100% of the code (i.e. you are using dependencies like ThreeJS, or React, or whatever) and changing the code to fix the warnings is not an option. And in many cases the warnings are not important, sometimes an argument is left in a function for stylistic choices (i.e. for users reading the code) and it is perfectly acceptable for a compressor to remove it. eg:
function tick (dt) {
// even though dt is not used, it is nice to leave it so
// readers know what is being passed
}
I just got confused because I received a few "Dropping unused function" and "Dropping unused variable" warnings, and I was sure the pointed functions and variables were purposeful.
I ran the result through a beautifier and understood the issue.
As it turns out, these functions and variables were used only once, and they have been inlined. Which is very great. But the warning messages brought confusion, they should have been something like "Inlined function/variable".
Yes, WARN is a bit harsh - it could be INFO. It's a historical thing.
But it would be nice, indeed, if it didn't issue a warning or info at all, if the case is a function dropped because it was inlined.
Most helpful comment
Or send
warnings=falseto the compressor, i.e.: