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 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.
An alternate solution is to add the following CSS style:
iframe
{
display: none;
}
This prevents the error from showing.
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.
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(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
Error overlays in create-react-app should now be disabled.
You can suppress React's error event handling by capturing the event first.
for example, by placing in public/index.html's <head>:
<script>
window.addEventListener('error', function(e){
// prevent React's listener from firing
e.stopImmediatePropagation();
// prevent the browser's console error message
e.preventDefault();
});
</script>
Since you probably still want React's error overlay for errors outside the error boundary, consider this option:
<script>
window.addEventListener('error', function(e){
const {error} = e;
if (!error.captured) {
error.captured = true;
e.stopImmediatePropagation();
e.preventDefault();
// Revisit this error after the error boundary element processed it
setTimeout(()=>{
// can be set by the error boundary error handler
if (!error.shouldIgnore) {
// but if it wasn't caught by a boundary, release it back to the wild
throw error;
}
})
}
});
</script>
assuming your error boundary does something like:
static getDerivedStateFromError(error) {
error['shouldIgnore'] = true;
return { error };
}
The result is a behaviour that follows try...catch line of reasoning.
To solve this issue, you could use CSS:
body > iframe {
display: none !important;
}
for some reason the overlay popped up for me only now while upgrading to Webpack 5.
In any case, you can now cancel the overlay by adding in your webpack.config.js:
module.exports = {
//...
devServer: {
client: {
overlay: false,
},
},
};
Or through the CLI: npx webpack serve --no-client-overlay
Taken from here: https://webpack.js.org/configuration/dev-server/#overlay
To avoid bundling in this large dev library in prod you can use a
dynamic import:
yarn add react-error-overlay
if (process.env.NODE_ENV === 'development') {
import('react-error-overlay').then(m => {
m.stopReportingRuntimeErrors();
});
}
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'),
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.
In the file webpack.config.js, comment the line:
// require.resolve('react-dev-utils/webpackHotDevClient'),
And uncomment:
require.resolve('webpack-dev-server/client') + '?/',
require.resolve('webpack/hot/dev-server'),
In the file webpackDevServer.config.js, comment:
// transportMode: 'ws',
// injectClient: false,
hide it with adblock
It is very useful to disable the errors temporarily so you don't have to comment/uncomment parts of your code that is not used at the moment, but it definitely will be after a few more changes.
The quickest solution is to just use adblock to pick the iframe with the errors.
It is trivial to toggle it with a single click to enable / disable adblock on the given page.
It is counter-intuitive to overlay the rendered page in development mode just to inform the user the newly imported objects or the recenlty created variables are not yet used.
I would say it is an arrow to the knee for beginners :)
If you are using the latest version with react-script >= 5.0.0, you just need to add an environment variable ESLINT_NO_DEV_ERRORS=true.
https://create-react-app.dev/docs/advanced-configuration
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
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.
Gathering answers here together, I managed to solve this issue for myself.
Here is the package I created for this.
The css fix has changed:
body > hmr-error-overlay {
display: none;
}
I'll also recommend adding this block on init so that you don't get silent errors:
window.addEventListener('error', function (e) {
console.error(e.message);
// prevent React's listener from firing
e.stopImmediatePropagation();
// prevent the browser's console error message
e.preventDefault();
});
Does anyone know how to remove the annoying "deprecations" word in the right bottom corner from Atom IDE?.
You can easily remove it. File => Settings => Packages => Core Packages => Deprecation Cop => Disable
I've seen where the deprecated call is part of Atom itself:
It could also be due to an incompatible package but troubleshooting those becomes an endless chore. Thankfully it's possible to edit the css:
Atom->Stylesheet... (styles.less)
Before:
I found that changing the text color from orange to default was enough for me:
.deprecation-cop-status {
color: inherit;
}
You can also hide it completely (use visibility: hidden; to preserve width if desired):
.deprecation-cop-status {
display: none;
}
Just click on the deprecation word, and it should open a new tab telling you what's wrong. Update or delete the package that causes the deprecations and the word will be removed.
I have a very strange problem with rendering PDF working everywhere, but not on prod. Developer and test environments are working without problems, but prod just can't handle it. The only changes that are now on prod: higher Grails version than the last war (2.1.0->2.3.8 [but this change has been introduced to the test environment ~2 months ago and all the problems were resolved then]) with few upgraded plugins, especially
compile ":rendering:0.4.3"
changed to
compile ":rendering:1.0.0"
Stacktrace I get on prod:
java.lang.NullPointerException
at org.xhtmlrenderer.swing.NaiveUserAgent.getBinaryResource(NaiveUserAgent.java:228)
at org.xhtmlrenderer.pdf.ITextFontResolver.importFontFaces(ITextFontResolver.java:97)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:178)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
at grails.plugin.rendering.pdf.PdfRenderingService.doRender(PdfRenderingService.groovy:36)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:43)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:37)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:35)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:65)
at GrailsMelodyGrailsPlugin$_closure4_closure16_closure17.doCall(GrailsMelodyGrailsPlugin.groovy:184)
at RenderingGrailsPlugin$_closure3.doCall(RenderingGrailsPlugin.groovy:59)
at com.my.app.ReportController$_closure8.doCall(ReportController.groovy:169)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:150)
at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:285)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:198)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:176)
My ReportController method for generating pdfs (nothing's really happening here and, yes, pdfShow file starts with an underscore):
def generatePdf = {
if (!params.id) {
throw new IllegalArgumentException("PDF Generation: an instance identifier has not been passed.")
}
def reportInstance = Report.findById(params.id)
renderPdf(template: "pdfShow", model: [reportInstance: reportInstance], filename: reportInstance?.reportFilename + '.pdf')
}
I have already done quite some research and found indications that it might be the problem with fonts declared in .css file which is used by the pdf template.
Well, this is the .css:
#font-face {
src: url("../fonts/DejaVuSansCondensed.ttf");
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
#font-face {
src: url(../fonts/DejaVuSansCondensed-Bold.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
body {
font-family: "DejaVu Sans Condensed", Arial, sans-serif;
}
And the fonts are there, both on test and prod. And did not change their location.
I have tried downgrading rendering plugin back to 0.4.3, but it didn't work, complaining about not available classes:
plugins\rendering-0.4.3\grails-app\services\grails\plugin\rendering\document\XhtmlDocumentService.groovy: 20: unable to resolve class org.xhtmlrenderer.resource.XMLResource
(...)\plugin\rendering\pdf\PdfRenderingService.groovy: 25: unable to resolve class com.lowagie.text.pdf.BaseFont
(...)\plugin\rendering\pdf\PdfRenderingService.groovy: 19: unable to resolve class org.xhtmlrenderer.pdf.ITextRenderer
...and few others etc.
setting in the BuildConfig.groovy
legacyResolve true
inside grails.project.dependency.resolution { ... also did not work.
Do you have any idea what could be wrong?
The thing which solved the problem, was adding one line to the Config.groovy:
environments {
production {
(...)
grails.resources.processing.enabled = false
We had this line in the test and development environments, but before, with Grails 2.1.0 it worked anyway.
I've been struggling with this for a few hours now. I have the following in my gulpfile:
gulp.task('styles', function() {
gulp.src('C:\\TeamCity\\buildAgent\\work\\5003e8de5901599\\dev\\Content\\css\\less\\dealer-landing.less')
.pipe(less())
.pipe(gulp.dest('C:\\TeamCity\\buildAgent\\work\\5003e8de5901599\\dev\\Content\\css'));
});
I run 'gulp styles' which completes with no errors, but the .css is never created. I tried simply commenting out the middle line as seen below and that works as expected; the less file gets copied to the dest directory:
gulp.task('styles', function() {
gulp.src('C:\\TeamCity\\buildAgent\\work\\5003e8de5901599\\dev\\Content\\css\\less\\dealer-landing.less')
//.pipe(less())
.pipe(gulp.dest('C:\\TeamCity\\buildAgent\\work\\5003e8de5901599\\dev\\Content\\css'));
});
Any idea why gulp-less doesn't generate the css? If I use just less, the file is generated correctly.
I experienced this due to an undefined class in my less file.
I discovered the undefined class through logging.
Gulp may not throw errors unless you explicitly log them. To log, require gulp-util in your gulpfile:
var util = require('gulp-util');
And then add logging:
.pipe(less().on('error', util.log)),
Run gulp style to see the error (possibly an undefined class).
Fix it and your style task should generate the css.
I got my less files compiled in css perfectly by grunt and I see result in .tmp/public/styles
So now livereload with grunt-contrib-watch should be made naturally in sails generated project ?
Or do I have to make a special configuration ?
I found that in tasks/pipeline.js file but not sure of what to do.
// CSS files to inject in order
//
// (if you're using LESS with the built-in default config, you'll want
// to change `assets/styles/importer.less` instead.)
var cssFilesToInject = [
'styles/**/*.css'
];
I saw in the file tasks/README.md :
###### `sails lift`
Runs the `default` task (`tasks/register/default.js`).
And in the file default.js we got :
module.exports = function (grunt) {
grunt.registerTask('default', ['compileAssets', 'linkAssets', 'watch']);
};
But watch.js file is missing in the folder...
What should it be ?
Watch does only looking for files that have changed and execute less, sass, injection and so on - but it doesn't make a reload.
You can add this in task/config/watch.js