{"id":17911,"library":"redux-raven-middleware","title":"Redux Sentry Middleware (Legacy)","description":"Redux middleware for sending error reports to Sentry through raven-js. This package, currently at version 1.2.0, was last published in January 2017, making it effectively abandoned. It automatically intercepts JavaScript errors that occur during action dispatch, capturing the error, the action that caused it, and the entire Redux application state for detailed crash reports. A key differentiating feature at the time was its deep integration with Redux state for context. However, its core dependency, `raven-js`, was officially deprecated by Sentry in Q2 2020 in favor of the modern `@sentry/browser` SDK. This means while the middleware itself may technically still function with older Sentry setups, it relies on a legacy library that no longer receives updates and lacks many features of the current Sentry ecosystem. Users should consider migrating to `redux-sentry-middleware` or a custom solution built with `@sentry/browser` for modern Sentry integration.","status":"abandoned","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/ngokevin/redux-raven-middleware","tags":["javascript","react","redux","raven","raven-js","sentry","middleware","crash","error"],"install":[{"cmd":"npm install redux-raven-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add redux-raven-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-raven-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for interacting with Sentry, but `raven-js` itself is deprecated.","package":"raven-js","optional":false}],"imports":[{"note":"This package exports a default function. For CommonJS, `require('redux-raven-middleware')` directly resolves to the middleware function.","wrong":"import { RavenMiddleware } from 'redux-raven-middleware';\n// Or for CommonJS:\nconst RavenMiddleware = require('redux-raven-middleware'); // Will return the function directly due to module.exports behavior","symbol":"RavenMiddleware","correct":"import RavenMiddleware from 'redux-raven-middleware';"},{"note":"Standard named import from Redux library.","wrong":"const applyMiddleware = require('redux').applyMiddleware;","symbol":"applyMiddleware","correct":"import { applyMiddleware } from 'redux';"},{"note":"Standard named import from Redux library.","wrong":"const createStore = require('redux').createStore;","symbol":"createStore","correct":"import { createStore } from 'redux';"}],"quickstart":{"code":"import { applyMiddleware, createStore } from 'redux';\nimport RavenMiddleware from 'redux-raven-middleware';\n\n// A dummy reducer for demonstration purposes\nconst initialState = { count: 0 };\nfunction rootReducer(state = initialState, action) {\n  switch (action.type) {\n    case 'INCREMENT':\n      // Intentionally cause an error for testing Sentry integration\n      if (action.fail) {\n        throw new Error('Simulated Redux error!');\n      }\n      return { ...state, count: state.count + 1 };\n    default:\n      return state;\n  }\n}\n\n// Replace 'YOUR_SENTRY_DSN' with your actual DSN, ideally from environment variables\nconst SENTRY_DSN = process.env.SENTRY_DSN ?? 'https://examplePublicKey@o0.ingest.sentry.io/0';\n\nconst createStoreWithMiddleware = applyMiddleware(\n  RavenMiddleware(SENTRY_DSN, {\n    // Optional Sentry configuration\n    environment: process.env.NODE_ENV || 'development',\n  }, {\n    // Optional middleware configuration\n    actionTransformer: action => {\n      // Prevent sensitive data from being sent to Sentry\n      if (action.type === 'LOGIN' && action.payload && action.payload.password) {\n        return { ...action, payload: { ...action.payload, password: '[REDACTED]' } };\n      }\n      return action;\n    },\n    stateTransformer: state => {\n      // Limit the size of the state sent to Sentry to avoid 'Request too large' errors\n      return { sensitiveData: '[REDACTED]', count: state.count };\n    },\n    logger: console.warn // Use console.warn instead of console.error for internal logs\n  })\n)(createStore);\n\nconst store = createStoreWithMiddleware(rootReducer);\n\nconsole.log('Initial state:', store.getState());\nstore.dispatch({ type: 'INCREMENT' });\nconsole.log('State after increment:', store.getState());\n\ntry {\n  store.dispatch({ type: 'INCREMENT', fail: true });\n} catch (e) {\n  console.error('Caught expected error from Redux dispatch:', e.message);\n  // Sentry would have captured this error via the middleware\n}\n\n// To run this, ensure 'raven-js' is installed: npm install raven-js\n// Set SENTRY_DSN environment variable or replace placeholder.\n","lang":"javascript","description":"Demonstrates setting up `redux-raven-middleware` with `applyMiddleware`, including options for transforming actions and state, and intentionally triggering an error to show Sentry integration."},"warnings":[{"fix":"Migrate to `redux-sentry-middleware` or implement a custom Redux middleware using `@sentry/browser` or `@sentry/react` (for React applications) to ensure compatibility with current Sentry features and security updates.","message":"The underlying `raven-js` library is officially deprecated by Sentry in favor of `@sentry/browser`. This package will not work with modern Sentry SDKs without significant rework and `raven-js` receives no further updates or new features.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider alternatives like `redux-sentry-middleware` which is an API-compatible fork supporting the modern Sentry SDKs, or roll your own integration using the official Sentry SDKs.","message":"This package is effectively abandoned, with its last update occurring over 9 years ago (January 2017). It is not maintained, and there are open issues on its GitHub repository.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Utilize the `stateTransformer` option within the middleware to prune or serialize the state before sending, including only relevant debugging information. For example, `{ stateTransformer: state => ({ user: state.user.id, currentRoute: state.router.location.pathname }) }`.","message":"Sending the entire Redux state can lead to 'Request too large' errors from Sentry, especially with complex or large state trees. Sentry has payload limits (e.g., 100 KB per event).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure `RavenMiddleware` is one of the first arguments passed to `applyMiddleware` in your Redux store configuration.","message":"The `RavenMiddleware` should generally be placed early in the `applyMiddleware` chain. If placed after other middleware that might throw errors (e.g., `redux-thunk`), those errors might not be captured by `redux-raven-middleware`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When migrating to modern Sentry SDKs, review Sentry's current documentation for setting user context, tags, and extra data, which typically involves `Sentry.setUser()`, `Sentry.setTag()`, `Sentry.setContext()`, or using `beforeSend` callbacks.","message":"Sentry's API and best practices for configuring context (e.g., user, tags, extra data) have evolved significantly since this middleware was last updated. This package uses older `raven-js` methods (like `Raven.config`) which may not align with current `@sentry/browser` SDK patterns.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `raven-js` is properly configured and installed before the Redux store is created and `redux-raven-middleware` is applied. Check for duplicate `raven-js` bundles or incorrect DSNs.","cause":"This error occurs when `Raven.config().install()` has not been called or has failed before `redux-raven-middleware` attempts to initialize or capture an error.","error":"Error: Raven has not been configured."},{"fix":"Use the `stateTransformer` and `actionTransformer` options to filter, redact, or reduce the size of the Redux state and action objects before they are sent to Sentry.","cause":"The data payload (especially the Redux state and action) being sent to Sentry exceeds Sentry's maximum allowed event size (typically 100 KB).","error":"HTTP Error: 413 Request Entity Too Large"},{"fix":"Verify that `raven-js` is correctly installed, imported, and initialized in your application. If `raven-js` is loaded via a `<script>` tag, ensure it's loaded before your application code that uses `redux-raven-middleware`.","cause":"This usually indicates that `Raven` from `raven-js` is not available in the global scope or correctly imported when `redux-raven-middleware` tries to access it.","error":"TypeError: Cannot read properties of undefined (reading 'config')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}