Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating sentry electron using ESM: regression caused for electron-updater: require is not defined #1043

Open
3 tasks done
CatStudioApp opened this issue Dec 27, 2024 · 1 comment

Comments

@CatStudioApp
Copy link

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Electron SDK Version

5.9.0

Electron Version

33.2.1

What platform are you using?

MacOS

Link to Sentry event

No response

Steps to Reproduce

We're using this template: https://github.com/electron-vite/electron-vite-react.git

import * as Sentry from "@sentry/electron/main";

export async function initSentry() {
  Sentry.init({
    debug: import.meta.env.DEV,
    environment: import.meta.env.DEV ? "development" : "production",
    dsn: "xxx",
  });
}

btw, this can work around this bug:

import { createRequire } from "node:module";

const require = createRequire(import.meta.url);

export function initSentry() {
  const Sentry = require("@sentry/electron/main");
  const log = require("electron-log");
  Sentry.init({
    debug: true,
    environment: import.meta.env.DEV ? "development" : "production",
    dsn: "xxx",
  });
  log.info("Sentry initialized");
}

initSentry();

Expected Result

everything should work

Actual Result

electron-updater stopped from working after integrating sentry electron.
require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 27, 2024
@timfish timfish self-assigned this Dec 30, 2024
@timfish
Copy link
Collaborator

timfish commented Jan 1, 2025

Sorry, you will need to supply a more complete example because I can't reproduce this issue when I add Sentry to the above repository.

For reference, I checked out the above repo and made these changes and don't get any build or runtime errors:
electron-vite-react-c56d5f3-Sentry-working.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants