React Transform Catch Errors
This package is a Babel transform designed to catch errors within React component `render()` functions during development, preventing application crashes and displaying a custom error UI. It operates as part of the `babel-plugin-react-transform` ecosystem, requiring both that plugin and a separate error reporting component (e.g., `redbox-react`) for full functionality. The latest stable version, 1.0.2, was released in February 2016. This tool was part of an earlier generation of React development experience utilities, largely superseded by modern solutions like React Fast Refresh (introduced with React 17 and actively supported by tools like Create React App) and React Error Boundaries. Its release cadence was infrequent, and the project is considered unmaintained, reflecting a shift in the React ecosystem towards more integrated, native hot-reloading and error handling mechanisms. It provided a configurable error display layer during development, a key differentiator in its time, by allowing developers to plug in custom error UIs.
Common errors
-
Error: Cannot find module 'babel-plugin-react-transform'
cause The essential `babel-plugin-react-transform` package, which orchestrates this transform, is not installed.fixInstall it as a development dependency: `npm install --save-dev babel-plugin-react-transform`. -
Uncaught Error: imports[1] for react-transform-catch-errors does not look like a React component.
cause This error typically indicates a version mismatch between `react-transform-catch-errors`, `redbox-react`, or related `react-transform` packages, or an incorrect path to the error reporter.fixEnsure `react-transform-catch-errors`, `redbox-react`, and `babel-plugin-react-transform` are installed with compatible versions. Try removing caret (`^`) from version numbers in `package.json`, clearing npm cache (`npm cache clean --force`), deleting `node_modules`, and reinstalling (`npm install`). Verify the path to your error reporter in `.babelrc` is correct and resolvable. -
Production bundle includes development-only error catching logic, increasing bundle size.
cause The `react-transform-catch-errors` configuration is not scoped to the `development` environment in your `.babelrc` file.fixWrap the `react-transform` plugin configuration inside an `env.development` block in your `.babelrc` to ensure it's only active when `process.env.NODE_ENV` is set to 'development'.
Warnings
- breaking Starting with v1.0.0, this transform no longer acts as a no-op in production environments. It is now explicitly your responsibility to ensure it's only enabled in development builds.
- deprecated The `react-transform` ecosystem, including `react-transform-catch-errors`, is largely abandoned and superseded by modern React development tools such as React Fast Refresh (introduced with React 17) and built-in React Error Boundaries. Using this package in new projects is not recommended.
- gotcha This package requires `babel-plugin-react-transform` to function, as it's a transform *for* that plugin, not a standalone Babel plugin. It also requires a separate error reporter package (e.g., `redbox-react`) to display errors.
- gotcha Errors in event handlers, asynchronous code (e.g., `setTimeout`), server-side rendering, or within the error boundary component itself are not caught by this transform or even native React Error Boundaries.
Install
-
npm install react-transform-catch-errors -
yarn add react-transform-catch-errors -
pnpm add react-transform-catch-errors
Imports
- "react-transform-catch-errors"
import { catchErrors } from 'react-transform-catch-errors'; const catchErrors = require('react-transform-catch-errors');// Configured as a string in your .babelrc, not directly imported in JS
- "react"
import React from 'react-transform-catch-errors/react';
// Configured as a string in your .babelrc transforms.imports array
- "redbox-react"
import Redbox from 'react-transform-catch-errors/redbox-react';
// Configured as a string in your .babelrc transforms.imports array
Quickstart
{
"presets": ["es2015", "stage-0"],
"env": {
// Only enable in development environment
"development": {
"plugins": [
[
"react-transform",
{
"transforms": [
{
"transform": "react-transform-catch-errors",
"imports": [
"react",
"redbox-react"
// Optional third import for reporter options:
// , "./my-reporter-options"
]
}
// Add other react-transforms here if needed, e.g., react-transform-hmr
]
}
]
]
}
}
}