Disable error overlay in development mode

前端 未结 11 981
长情又很酷
长情又很酷 2020-11-30 08:08

Is there a way to disable the error overlay when running a create-react-app in development mode?

This is the overlay I\'m talking about:

I\'m askin

11条回答
  •  难免孤独
    2020-11-30 09:09

    The error overlay can be disabled by using the stopReportingRuntimeErrors helper utility in the react-error-overlay package.

    First, install the react-error-overlay package:

    yarn add react-error-overlay
    

    Then in index.js — right before mounting the root React component, import the utility and invoke it like this:

    import { stopReportingRuntimeErrors } from "react-error-overlay";
    
    if (process.env.NODE_ENV === "development") {
      stopReportingRuntimeErrors(); // disables error overlays
    }
    
    ReactDOM.render(
      
        
      ,
      document.getElementById("root")
    );
    

    Error overlays in create-react-app should now be disabled.

提交回复
热议问题