Skip to content

Infinite error loop with modulesIntegration in ESM #14165

Closed
@kyranet

Description

@kyranet

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.36.0

Framework Version

Node.js v22.11.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from '@sentry/node';

Sentry.init({
	dsn: envParseString('SENTRY_URL'),
	integrations: [
		Sentry.consoleIntegration(),
		Sentry.functionToStringIntegration(),
		Sentry.linkedErrorsIntegration(),
		Sentry.modulesIntegration(),
		Sentry.onUncaughtExceptionIntegration(),
		Sentry.onUnhandledRejectionIntegration(),
		Sentry.httpIntegration({ breadcrumbs: true }),
		Sentry.prismaIntegration(),
		Sentry.rewriteFramesIntegration({ root: rootFolder })
	]
});

Steps to Reproduce

  1. Make an ESM-only Node.js application
  2. Setup the SDK as shown above
  3. Catch an exception (e.g. with captureException())
  4. Watch Sentry get into an infinite loop, using 100% CPU

Expected Result

Everything works as expected and an incident is created in the dashboard.

Actual Result

It doesn't create the incident... nor it responds, because:

The collectModules() function uses require even in the ESM version, where it's not defined: https://yarnpkg.com/package?q=%40sentry%2Fnode&name=%40sentry%2Fnode&file=%2Fbuild%2Fesm%2Fintegrations%2Fmodules.js

This causes whatever code is calling to throw an error over and over:

ReferenceError: require is not defined
    at collectModules (app\node_modules\@sentry\node\src\integrations\modules.ts:42:21)
    at _getModules (app\node_modules\@sentry\node\src\integrations\modules.ts:93:19)
    at Object.processEvent (app\node_modules\@sentry\node\src\integrations\modules.ts:16:12)
    at Object.assign.id (app\node_modules\@sentry\core\src\integration.ts:139:105)
    at <anonymous> (app\node_modules\@sentry\core\src\eventProcessors.ts:20:22)
    at new SyncPromise (app\node_modules\@sentry\utils\src\syncpromise.ts:59:7)
    at notifyEventProcessors (app\node_modules\@sentry\core\src\eventProcessors.ts:15:10)
    at <anonymous> (app\node_modules\@sentry\core\src\eventProcessors.ts:26:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Which is repeated indefinitely, ramping the CPU usage to 100% and making the application not respond.

Removing Sentry.modulesIntegration() from the integrations list resolves this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions