Skip to content

import hook incompatible with tsx #12011

Closed
@nwalters512

Description

@nwalters512

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

Framework Version

No response

Link to Sentry event

No response

SDK Setup

Sentry.init({
  dsn: 'https://[email protected]/0',
});

Steps to Reproduce

I've created a minimal reproduction here: https://github.com/nwalters512/sentry-v8-tsx-error-repro

  1. Clone the repository
  2. Install dependencies with yarn
  3. Run yarn tsx src/index.ts
  4. Observe that the process fails with the error TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file

Several observations that are hopefully helpful to y'all:

  • This only occurs when "allowJs": true is set in tsconfig.json. As Sentry isn't concerned with this, that made me think this problem might actually be in tsx. However...

  • When adding instrumentation directly with the @opentelemetry/* packages, everything works fine. This is reproducible by making the following change to src/index.ts:

    -import './instrument-sentry.js';
    +import './instrument-opentelemetry.js';

    Given this, I'm strongly inclined to believe that this is an issue with the way in which Sentry is using OpenTelemetry.

  • This only breaks for core Node modules like util, fs, etc. Importing other modules works fine. For instance, the following change to src/index.ts makes it work without erroring:

    -await import('util');
    +await import('zod');
  • This only breaks for dynamic imports. For instance, the following change to src/index.ts makes it work without erroring:

    -await import('util');
    +import 'util';

Expected Result

I would expect the process to complete successfully and log util imported!.

Actual Result

The process errors out while importing util and does not print util imported!.

Metadata

Metadata

Assignees

No one assigned

    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