Skip to content

fsIntegration crashes in native ESM when patching the read-only fs namespace #25950

Open

Description

@utrumo

Environment

  • @sentry/node 11.10.0
  • Node.js 24.22.1, Linux x64
  • Native ESM, no bundler

Minimal reproduction

import { fsIntegration } from '@sentry/node';
fsIntegration().setupOnce?.();

Run with node --input-type=module (or save as .mjs). The same failure occurs when registering fsIntegration() through Sentry.init().

Actual behavior

The process throws asynchronously:

TypeError: Cannot assign to read only property 'accessSync' of object '[object Module]'

The stack points to _patchMethod in build/esm/integrations/fs/vendored/instrumentation.js.

Expected behavior

Filesystem instrumentation initializes in native ESM without crashing.

Cause and workaround

The ESM implementation imports * as fs from 'fs' and then assigns wrappers to that read-only module namespace. Loading the integration from the public CommonJS build with createRequire() works. Using the mutable default fs export fixes the crash; calling syncBuiltinESMExports() afterward also refreshes named ESM bindings.

Activity

  1. linear-code commented on Oct 30, 2026

    @linear-code
  2. utrumo commented on Oct 30, 2026

    @utrumo
    Author

    I'd like to submit a small fix: use the mutable default fs export and refresh named ESM bindings with syncBuiltinESMExports().

    The existing filesystem integration tests currently run only in CommonJS; I'd extend coverage to native ESM, including named imports. I've verified the fix locally.

    Would you be happy for me to open a draft PR against develop?

  3. self-assigned this
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions