TypeScript Errors due to dependency woes
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]
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 is there an issue in otel that describes the removal of the types dependencies?
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 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 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.
v10 now uses otel v2, and all the latest instrumentation packages, so this should hopefully be fixed there!