Search code examples
typescriptinternet-explorerangular5angular-cli

Disabling console.log() in production


I have run the following to disable console logs for production environments in my angular application. The below code works as expected for chrome, however, it still shows logs in IE 11.

main.ts

if (environment.production) {
  enableProdMode();
if(window){
  window.console.log=function(){};
 }
}

Is this a polyfill issue? I wasn't able to find anything online about it.

EDIT

This question may seem similar but does not address my issue as to why overriding the console log function to a blank method works in chrome but not IE 11.


Solution

  • Solution is to add the polyfill to your polyfill.ts file

    if(!window.console) {
     var console = {
      log : function(){},
      warn : function(){},
      error : function(){},
      time : function(){},
      timeEnd : function(){}
     }
    }