Skip to content

[Bug]: "Cannot set property of X which has only a getter" when inlineDynamicImports is set to true #5449

Description

@spaceemotion

Reproduction link or steps

This is likely an issue with Sentry and how they're patching OpenTelemetry in via module imports/requires. I only got the error to appear when importing the AWS DynamoDB client as well, likely because it also has something to do with HTTP tracing?

StackBlitz: https://stackblitz.com/edit/rolldown-rolldown-starter-stackblitz-vxqueybk?file=package.json

Run the above project with Node v22 - I couldn't get it to break with Node v20.

What is expected?

No errors when executing final build.

What is actually happening?

If the config option output.inlineDynamicImports is set to true, running the final output file will throw this error:

> cd dist && SENTRY_DSN=test_smoke node --input-type=commonjs -e 'import("./lambda.cjs").then((m) => m.handler).catch((e) => { console.error(e); process.exit(1); });'

Application entry
Initializing Sentry release "undefined" for environment: undefined
Sentry Logger [log]: Initializing Sentry: process: 55334, thread: main.
Invalid Sentry Dsn: test_smoke
Sentry Logger [log]: Running in CommonJS mode.
TypeError: Cannot set property _eventsCount of #<process> which has only a getter
    at _addListener (node:events:576:14)
    at process.addListener (node:events:612:10)
    at NodeClient.startClientReportTracking (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:25824:12)
    at _init$1 (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:25907:11)
    at init$1 (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:25886:9)
    at _init (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:28539:19)
    at initWithoutDefaultIntegrations (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:28553:9)
    at init (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:30109:9)
    at Object.<anonymous> (/home/spaceemotion/code/xxxxxx/dist/maintenance-BWNAcPUh.cjs:30268:2)
    at Module._compile (node:internal/modules/cjs/loader:1434:14)

Once the inlining is disabled, it runs just fine:

> cd dist && SENTRY_DSN=test_smoke node --input-type=commonjs -e 'import("./lambda.cjs").then((m) => m.handler).catch((e) => { console.error(e); process.exit(1); });'

Application entry
Initializing Sentry release "undefined" for environment: undefined
Sentry Logger [log]: Initializing Sentry: process: 56122, thread: main.
Invalid Sentry Dsn: test_smoke
Sentry Logger [log]: Running in CommonJS mode.
Sentry Logger [log]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [log]: @opentelemetry/api: Registered a global for trace v1.9.0.
Sentry Logger [log]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Sentry Logger [log]: @opentelemetry/api: Registered a global for context v1.9.0.
Building lambda handler
Creating server
Waiting for server to be ready
Server is ready after 18ms (Total time: 138ms)
Sentry Logger [log]: Flushing outcomes...
Sentry Logger [log]: No outcomes to send

System Info

System:
    OS: Linux 6.6 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 13.76 GB / 23.47 GB
    Container: Yes
    Shell: 3.6.1 - /usr/bin/fish
  Binaries:
    Node: 22.2.0 - /mnt/wslg/runtime-dir/fnm_multishells/252_1753527662487/bin/node
    npm: 10.7.0 - /mnt/wslg/runtime-dir/fnm_multishells/252_1753527662487/bin/npm
    pnpm: 8.15.5 - /mnt/wslg/runtime-dir/fnm_multishells/252_1753527662487/bin/pnpm
    bun: 1.1.8 - ~/.bun/bin/bun
  npmPackages:
    rolldown: 1.0.0-beta.29 => 1.0.0-beta.29

Any additional comments?

The Sentry function causing the issue is the following:

/**
* Will start tracking client reports for this client.
*
* NOTICE: This method will create an interval that is periodically called and attach a `process.on('beforeExit')`
* hook. To clean up these resources, call `.close()` when you no longer intend to use the client. Not doing so will
* result in a memory leak.
*/
startClientReportTracking() {
  const clientOptions = this.getOptions();
  if (clientOptions.sendClientReports) {
    this._clientReportOnExitFlushListener = () => {
      this._flushOutcomes();
    };
    this._clientReportInterval = setInterval(() => {
      DEBUG_BUILD$2 && debug.log("Flushing client reports based on interval.");
      this._flushOutcomes();
    }, clientOptions.clientReportFlushInterval ?? DEFAULT_CLIENT_REPORT_FLUSH_INTERVAL_MS).unref();
    process.on("beforeExit", this._clientReportOnExitFlushListener); // <-- throws the error
  }
}

https://github.com/getsentry/sentry-javascript/blob/68d7ee4bbc5a28d693f065da4cc7656d8b044748/packages/node-core/src/sdk/client.ts#L112-L143

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions