Skip to content

SDK fails in ESM mode in combination with date-fns #12154

Closed
@Xhale1

Description

@Xhale1

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.2.1

Framework Version

Nodejs 20.13.1

Link to Sentry event

https://mycopilot.sentry.io/issues/5344731586/?project=6067364&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=24h&stream_index=0

SDK Setup

Sentry.init({
  dsn: "[REDACTED]",
});

Steps to Reproduce

  1. Upgrade from v7 to v8 following the migration docs
  2. Follow Sentry docs for ESM
  3. Add --import ./dist/instrument.js to the node command

Expected Result

Application starts up.

Actual Result

Application crashes with an error which seems to involve duplicate exports with ESM. An example of my particular error:

SyntaxError: Identifier '$longFormatters' has already been declared
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:169:18)
    at callTranslator (node:internal/modules/esm/loader:272:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:30)

Upon investigating, I found my error to be related to the date-fns package and this issue. Reverting date-fns to a version without a duplicate export results in another similar error (I suspect related to the openai package duplicate export though haven't confirmed).

This issue does not occur when using the --import flag to load a file without sentry code in it, and it doesn't surface elsewhere. This error may be due to other projects misusing ESM, though I hope since the issue only surfaces with Sentry instrumentation that it may be solvable here.

Metadata

Metadata

Assignees

Labels

Package: nodeIssues related to the Sentry Node SDK

Type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions