Skip to content

Outdated svelte2tsx dependency for @sveltejs/package #12517

@lachlancollins

Description

@lachlancollins

Describe the bug

Hi there, I've stumbled across an annoying issue using @sveltejs/package to generate types for svelte 5 components, related to the svelte2tsx semver range. I think this is the best place to post this issue since the change would need to be made in this repo.

Because of the way pnpm works, when @sveltejs/package updates, it does not update indirect dependencies that already match the semver range. The semver range of svelte2tsx is currently "~0.7.0", and hasn't been updated since #11619 (6 months ago).

At some point, the version of svelte2tsx in the TanStack Query repo got installed as v0.7.1. However, there are numerous new releases since then which have improved svelte 5 compatibility. When packaging svelte 5 components with this version of svelte2tsx, it is unable to generate the correct types (all props are unknown).

I can work around this problem by deleting pnpm-lock.yaml, which installs the latest svelte2tsx version (v0.7.13) and generates the correct types. However, I wonder if it would be better to keep svelte2tsx's semver range updated within @sveltejs/package so other library devs don't run into the problem. This could be automatically handled by renovate with the "rangeStrategy": "bump" option - for reference, this is also used by Astro's renovate config.

Reproduction

With svelte2tsx v0.7.1 installed as a dependency of @sveltejs/package, the following component Demo.svelte:

<script lang="ts">
  type Props = {
    foo: string
  }

  let { foo }: Props = $props()
</script>

<div>{foo}</div>

Generates the following type output:

import { SvelteComponent } from "svelte";
declare const __propDef: {
    props: {
        foo: unknown;
    };
    events: {
        [evt: string]: CustomEvent<any>;
    };
    slots: {};
};
export type DemoProps = typeof __propDef.props;
export type DemoEvents = typeof __propDef.events;
export type DemoSlots = typeof __propDef.slots;
export default class Demo extends SvelteComponent<DemoProps, DemoEvents, DemoSlots> {
}
export {};

Logs

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 12.49 GB / 15.58 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.11.0 - ~/.volta/tools/image/node/20.11.0/bin/node
    npm: 10.2.5 - ~/.volta/tools/image/npm/10.2.5/bin/npm
    pnpm: 9.5.0 - ~/.volta/bin/pnpm
  npmPackages:
    @sveltejs/package: ^2.3.1 => 2.3.1 
    @sveltejs/vite-plugin-svelte: ^4.0.0-next.5 => 4.0.0-next.5 
    svelte: ^5.0.0-next.200 => 5.0.0-next.200

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions