Issue
I have a React app packaged with Electron and I need to know whether to install @sentry/react, @sentry/electron, or both.
Applies To
All SaaS Customers and Self-Hosted Users
Electron SDK (
@sentry/electron)React SDK (
@sentry/react)SDK Setup
Resolution
Use both packages. Install @sentry/electron for the Electron main and renderer processes. Install @sentry/react as well, and pass React's init into the Electron renderer init so React features work in the UI.
Do not call @sentry/react init on its own in an Electron renderer. That skips Electron IPC, native crash handling, and main-process capture.
Do not replace @sentry/electron with @sentry/node or @sentry/browser. Import @sentry/electron/main and @sentry/electron/renderer.
Install
@sentry/electronand@sentry/react.Call
initfrom@sentry/electron/mainin the main process, as early as possible.In each React renderer, call
initfrom@sentry/electron/rendererand pass React'sinitas the second argument.
import * as Sentry from "@sentry/electron/main";Sentry.init({
dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
});
import { init } from "@sentry/electron/renderer";
import { init as reactInit } from "@sentry/react";init(
{
// dsn, release, and environment on renderer init have no effect.
// Renderer events go through the main process.
integrations: [
/* integrations */
],
},
reactInit,
);
See Using Framework-Specific SDKs. If you need ErrorBoundary in the React tree, see Can Sentry.ErrorBoundary be used in an Electron app made with React?.
