React: Stop showing warnings as errors.

Created on 10 Dec 2015  路  13Comments  路  Source: facebook/react

I can't debug my own code because of the warnings spam. The warning spam is beyond my control because react router is having conflicts with history that they haven't resolved. It's very frustrating to experience this:

2015-12-09 at 3 36 pm

without having any recourse short of installing out of date deps. Show warnings as warnings. That's what console.warning is for.

Most helpful comment

I do agree with @Elijen. A warning should be logged via console.warn() rather than console.error(). That would make filtering in dev tools more convenient.

All 13 comments

if i recall correctly, React uses console.error so that you have access to the stack trace (https://github.com/facebook/react/issues/4216) Having said that, these errors aren't coming from React, they're coming from the history module (https://github.com/rackt/history/blob/83f1a6382bd03b04d334958f44be6c9362b920a5/modules/useQueries.js#L108-L111 ) using the warning module ( https://www.npmjs.com/package/warning )

As mentioned these are not coming from React but from something else (use the stack trace to find the guilty party). Encourage react-router or whomever to do some improvements to dedupe warnings (eg, in React, to reduce spam we attempt to dedupe on the type and location of the warning).

@zpao Why can't console.warning be used here? Stack trace is available using console.trace

There errors are, for example, coming from React:
screen shot 2016-07-21 at 12 10 47 am

They are coming from React Bootstrap, and next version will fix them.

@gaearon This is just an example. I know this error should be fixed by React Bootstrap, but what concerns me is the React behavior where _warnings_ are printed as _errors_ which makes debugging and development hard (can't filter these out from JS console).

That's why I think usage of console.warning should be considered.

react

@Elijen you're expected to prevent the warnings by fixing your code. If they're not actionable then that's a problem with those specific warnings, not warnings in general.

I do agree with @Elijen. A warning should be logged via console.warn() rather than console.error(). That would make filtering in dev tools more convenient.

Agree with this as well. We should all fix and prevent warnings of course, however the argument is a warning is not an error and shouldn't displayed as such.

+1 for this. It would be really nice to have warnings show up in the warnings tab in dev tools and not the errors tab.

maybe this code snippet would help some of you. I'm using this myself:

const errorsToWarn: string[] = [
    "Warning:",
];
const oldConsError = console.error;
console.error = function(...args: any) {
    let toWarn: boolean = false;

    if (typeof args[0] === 'string') {
        errorsToWarn.map(function(_s: string) {
            if (args[0].startsWith(_s)) {
                toWarn = true;
            }
        })
    }

    toWarn ? console.warn(...args) : oldConsError(...args);
}

2020 and still getting warning spammed :(

I can't believe it's 5 years later and this has never been fixed! Why not? Am I missing something?

Yeah I don't get it. My QA team isn't so concerned with whether or not we have a key on an element (although you may argue they should, that's another conversation), and digging through to find an actual error is time consuming.

Was this page helpful?
0 / 5 - 0 ratings