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

modulesIntegation throws error if used from ESM #12500

Closed
3 tasks done
timfish opened this issue Jun 15, 2024 · 1 comment · Fixed by #14169
Closed
3 tasks done

modulesIntegation throws error if used from ESM #12500

timfish opened this issue Jun 15, 2024 · 1 comment · Fixed by #14169
Assignees
Labels
Meta: Help Wanted Package: node Issues related to the Sentry Node SDK Type: Bug

Comments

@timfish
Copy link
Collaborator

timfish commented Jun 15, 2024

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

latest

Framework Version

No response

Link to Sentry event

No response

SDK Setup

modulesIntegration is excluded by default when using ESM but it can be added manually.

Steps to Reproduce

index.mjs

Sentry.init({
    dsn: '__DSN__',
    integrations: [
        Sentry.modulesIntegration(),
    ]
});

Expected Result

No error or at least an error that is more useful for debugging the issue.

Actual Result

This error in an endless loop:

ReferenceError: require is not defined
    at file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/core/esm/baseclient.js:632:15
    at Array.<anonymous> (file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:87:23)
    at file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:183:19
    at Array.forEach (<anonymous>)
    at SyncPromise._executeHandlers (file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:173:20)
    at SyncPromise._setResult (file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:161:10)
    at _reject (file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:144:10)
    at Array.<anonymous> (file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:84:13)
    at file:///Users/tim/Documents/Repositories/repro/node_modules/@sentry/utils/esm/syncpromise.js:183:19
    at Array.forEach (<anonymous> 
@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Jun 15, 2024
@AbhiPrasad AbhiPrasad self-assigned this Nov 4, 2024
AbhiPrasad added a commit that referenced this issue Nov 4, 2024
resolves #12500
resolves #14165

`modulesIntegration` uses top-level require which will crash ESM apps if
you explicitly import and use the integration.

```mjs
// index.mjs
Sentry.init({
    dsn: '__DSN__',
    integrations: [
        Sentry.modulesIntegration(),
    ]
});
```

This fixes that by adding a boolean check for cjs apps, and logging out
a warning as a result.
Copy link
Contributor

github-actions bot commented Nov 5, 2024

A PR closing this issue has just been released 🚀

This issue was referenced by PR #14169, which was included in the 8.37.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meta: Help Wanted Package: node Issues related to the Sentry Node SDK Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants