Skip to content

Conversation

@james-pre
Copy link

@james-pre james-pre commented Oct 29, 2025

This PR ignores errors when @opentelemetry/api is not installed since it is an optional dependency. Fixes #14774.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

🦋 Changeset detected

Latest commit: c83f9f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems okay to me, but we should probably have someone more knowledgeable with TypeScript weigh in

@james-pre
Copy link
Author

Given that @ts-ignore won't work, 4e32ec0 stubs the things imported by SvelteKit. pnpm check runs successfully, so this will hopefully fix the problem.

@james-pre james-pre requested a review from teemingc October 30, 2025 02:59
@teemingc
Copy link
Member

Given that @ts-ignore won't work, 4e32ec0 stubs the things imported by SvelteKit. pnpm check runs successfully, so this will hopefully fix the problem.

I'm not sure if that will work or if that did anything. Note that you'll have to test against the types found in node_modules/@sveltejs/kit/types/index.d.ts of your project. dts-buddy generates that file via the script in packages/kit/scripts/generate-dts.js.

@james-pre
Copy link
Author

Thanks for the tip! I've gone ahead and gotten a solution that results in the error being gone in a local project.

Comment on lines 3377 to 3387
declare module '@opentelemetry/api' {
export interface Span {}

export interface Tracer {}

export interface SpanContext {}

export interface PropagationAPI {}

export interface ContextAPI {}

Copy link
Member

@teemingc teemingc Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this but I think it removes the autocomplete for users when they do have @opentelemetry/api installed since these types then override the actual package.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a trade off. The alternative is that more users can't build at all unless they completely disable type-checking libraries. If there is a way to get autocomplete when it is installed without breaking dependents missing OTEL, I'm all for it.

I've created floating point airthmatic within the type system, yet this somehow is a harder problem...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should conditionally generate the stub by checking if @opentelemetry/api is installed 😆 otherwise, getting sveltejs/dts-buddy#110 merged would let us use // @ts-ignore even if it's frowned upon in that thread

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that being able to use @ts-ignore would be a better and easier solution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teemingc do you have any plans to merge the dts-buddy PR soon? If not I'd like to get this PR merged since it would fix the bug. We could look into using ts-ignore after your PR is merged.

Copy link
Member

@teemingc teemingc Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd need another maintainer to approve the dts-buddy PR to merge it. Even then, it seems like all the tests are failing after I've merged the main branch. I'll need to take a look at those. cc: @Rich-Harris

EDIT: we can't merge this PR as is because the stubs here will break the TypeScript autocomplete for users who do have otel installed

@svelte-docs-bot
Copy link

@teemingc teemingc added the needs-decision Not sure if we want to do this yet, also design work needed label Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-decision Not sure if we want to do this yet, also design work needed types / typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot find module '@opentelemetry/api' or its corresponding type declarations.

4 participants