Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: Browser Detection in ReactJS

Tags:

reactjs

I am having trouble while compiling a React JS project in some browsers. In Chrome it worked perfectly, but in firefox 63.0b14 i got this error: "? We're unable to detect target browsers."! As you can see it in the image.

error log

like image 844
Usman Khan Avatar asked Oct 16 '18 14:10

Usman Khan


People also ask

How does reactJs detect browser?

Check browser name For example, to get the browser name and version, we will import browserName and browserVersion from the library. import { browserName, browserVersion } from "react-device-detect"; If we log these two values to the console, we will see the following. console.

How do you catch errors in reactJs?

Error boundaries were introduced in React 16 as a way to catch and handle JavaScript errors that occur in the UI parts of our component. So error boundaries only catch errors that occur in a lifecycle method, render method, and inside Hooks like useEffect .

How does react handle API error?

Error handling with Error Boundaries — For class components. Error boundaries are the most straightforward and effective way to handle errors that occur within your React components. You can create an error boundary component by including the life cycle method componentDidCatch(error, info) if you use class component.

How can a developer react to and handle errors gracefully?

React provides two lifecycle methods that a component can implement to determine if a rendering error has occurred in its child tree and respond accordingly. These two methods are componentDidCatch() and static getDerivedStateFromError() .


1 Answers

Are you sure it's not due to upgrading react-scripts from v1 to v2, like explained here?

When you run npm start for the first time after the upgrade, you’ll get a prompt asking about which browsers you’d like to support. Press y to accept the default ones. They’ll be written to your package.json and you can edit them any time. Create React App will use this information to produce smaller or polyfilled CSS bundles depending on whether you target modern browsers or older browsers.

like image 114
oligopol Avatar answered Sep 18 '22 11:09

oligopol