sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

TypeScript Errors due to dependency woes

Open pfumagalli opened this issue 8 months ago • 5 comments

Is there an existing issue for this?

  • [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [x] I have reviewed the documentation https://docs.sentry.io/
  • [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

9.15.0

Framework Version

Node 20.19.1, TypeScript 5.8.3

Link to Sentry event

No response

Reproduction Example/SDK Setup

The @sentry/[email protected] package pulls in @opentelemetry/[email protected], which in turn pulls in @types/[email protected]. When compiling, I get this:

│ /home/runner/work/lib-api-framework/lib-api-framework/node_modules/@types/pg/index.d.ts
│   12:31  Cannot find module 'pg-protocol/dist/messages' or its corresponding type declarations. [TS2307]
│          | import { NoticeMessage } from 'pg-protocol/dist/messages';

The problem arises when building against @sentry/node with module resolution set to bundler, and it's rather annoying as we (for example) don't use any instrumentation.

Reported upstream here.

Steps to Reproduce

Set module resolution in tsconfig.json to bundler and run tsc

Expected Result

Types should compile

Actual Result

Got this error:

Cannot find module 'pg-protocol/dist/messages' or its corresponding type declarations. [TS2307]

pfumagalli avatar May 05 '25 14:05 pfumagalli

Hi, thanks for raising. Imo the OTEL instrumentation should probably not pull any types packages into the dependencies at all. We'll see if we can upstream the removal of the types packages from the dependencies.

lforst avatar May 06 '25 07:05 lforst

@lforst is there an issue in otel that describes the removal of the types dependencies?

phillipuniverse avatar May 29 '25 19:05 phillipuniverse

The types package seems to have been updated in the Otel pg instrumentation: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2816 and it ~was released~ will be released with version 0.54.0 of @opentelemetry/instrumentation-pg (release pending, see https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2834). Once it's released, we'll bump the dependency in our Node SDK.

side-note: I don't understand why this package needs to ship @types/pg at all, but not sure if we can get them to remove the dependencies all together.

Lms24 avatar May 30 '25 09:05 Lms24

@Lms24 sounds good! In the meantime this workaround got me out of the woods in package.json:

{
    "name": "mypackage",
    "version": "1.2.3",
    ...

    "overrides": {
        "@types/pg": "8.15.1"
    },
    ...
    "devDependencies": {
    ...
}

phillipuniverse avatar May 30 '25 12:05 phillipuniverse

@phillipuniverse Glad that you find a workaround with the override. Thanks for posting it! Unfortunately, I found out that we we cannot yet upgrade to the newest version. In version 0.52.0, Otel decided to break compatibility of the pg instrumentation with the OpenTelementry v1 SDK in favour of v2. The Sentry SDKs haven't yet upgraded to v2 because doing this in itself is another breaking change. So we'll need to wait for v10 of our SDKs to upgrade instrumentation further. Good news is, we're already working on that.

Lms24 avatar May 30 '25 12:05 Lms24

v10 now uses otel v2, and all the latest instrumentation packages, so this should hopefully be fixed there!

mydea avatar Aug 05 '25 08:08 mydea