How to Remove Errors Warnings from Console

Hide errors and warnings from console

You can handle errors to some extent but if error is not handled by you then it goes to browser and you can not stop browser showing it. You can write code in such a way that you get minimum error and using try-catch where possible to handle the exceptions.

//statements suspected to throw exception.

Is there any way to disable all the errors and warnings that appear in the console?

Since you are using React, my guess is you are already using babel. There's a plugin for that purpose. It's called babel-plugin-transform-remove-console. This will exclude all console.log's statement during the build process.

Install that in your app and configure it via .babelrc as follows:

"plugins": ["transform-remove-console"]

You can also specify the variant(s) of the console functions to exclude:

"plugins": [ ["transform-remove-console", { "exclude": [ "error", "warn"] }] ]

My advise is to not use console logs in your code except necessary.

Ignore certain console errors / warnings in React?

You can override the console.warn method with your own function that filters out the warnings you want to ignore:

const backup = console.warn;

console.warn = function filterWarnings(msg) {
const supressedWarnings = ['warning text', 'other warning text'];

if (!supressedWarnings.some(entry => msg.includes(entry))) {
backup.apply(console, arguments);

console.warn('I\'ll appear as a warning');

console.warn('warning text - I will not');

Hide warning messages in console window

Just recently there was a Chrome update. Now filtering single message types is possible (Verbose, Info, Warnings, Errors)! (My Version: Version 60.0.3112.90)

When opening the console, instead of selecting a "filter level", you can now check or uncheck each message type.

Screenshot of Console in Chrome

Related Topics

Leave a reply