Disable error overlay in development mode

2019-01-27 14:39发布

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:

enter image description here

I'm asking this because im using error boundaries (React 16 Error Boundaries) in my app to display error messages when components crashes, but the error overlay pops up and covers my messages.

5条回答
太酷不给撩
2楼-- · 2019-01-27 14:51

I had the same problem and I have been digging in the create-react-app source for a long time. I can't find any way to disable it, but you can remove the listeners it puts in place, which effectivly stops the error message. Open the developerconsole and select the html tag. There you can remove the event listeners on error and unhandlerejection which is put in place by unhandledError.js. You can also close the error message by clicking the x in the upper right corner of the screen, and then you should see your message.

查看更多
【Aperson】
3楼-- · 2019-01-27 14:52

We don't provide an option to disable the error overlay in development. Error boundaries do not take its place (they are meant for production use).

There is no harm having both the development error overlay and your error boundary; simply press [escape] if you'd like to view your error boundary.

We feel the error overlay provides tremendous value over your typical error boundary (source code, click to open, etc). It is also vital as we explore enabling hot component reloading as a default behavior for all users.

If you feel strongly about disabling the overlay, you'll need to eject from react-scripts and discontinue use of webpackHotDevClient. A less intrusive method may be removing the error event listener installed by the overlay off of window.

查看更多
相关推荐>>
4楼-- · 2019-01-27 14:54

In config/webpack.config.dev.js, comment out the following line in the entry array

require.resolve('react-dev-utils/webpackHotDevClient'),

And uncomment these two:

require.resolve('webpack-dev-server/client') + '?/',
require.resolve('webpack/hot/dev-server'),
查看更多
够拽才男人
5楼-- · 2019-01-27 14:59

There is no option for it.

But, if you strongly wanted to disable modal window, just comment out this line

https://github.com/facebook/create-react-app/blob/26f701fd60cece427d0e6c5a0ae98a5c79993640/packages/react-dev-utils/webpackHotDevClient.js#L173

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-27 15:01

I think this makes sense but sometimes when you are typing and have an error boundary then the overlay pops up with each character stroke and is annoying. I can remove the handler I suppose.

查看更多
登录 后发表回答