Skip to content

@sveltejs/package fails with "Invalid comparator" when using Bun workspace catalogs #13836

@handlebauer

Description

@handlebauer

Describe the bug

@sveltejs/package fails to build when package.json dependencies use Bun's workspace catalog syntax (e.g., "svelte": "catalog:svelte"). The tool attempts to parse catalog references as semver ranges, causing a build failure.

Context

  1. Set up a Bun workspace with catalogs in root package.json:
{
  "workspaces": {
    "catalogs": {
      "svelte": {
        "svelte": "^5.23.1",
        "@sveltejs/kit": "^2.16.0"
      }
    }
  }
}
  1. Create a package using @sveltejs/package with catalog references:
{
  "name": "my-package",
  "devDependencies": {
    "@sveltejs/package": "^2.3.7",
    "svelte": "catalog:svelte",
    "@sveltejs/kit": "catalog:svelte"
  },
  "scripts": {
    "build": "svelte-package"
  }
}
  1. Run bun run build

Expected behavior

@sveltejs/package should either:

  1. Resolve catalog references to their actual versions before processing, or
  2. Gracefully handle non-semver dependency specifications

Actual behavior

> Invalid comparator: catalog:svelte
at Comparator.parse (/path/to/node_modules/semver/classes/comparator.js:41:13)
at new Comparator (/path/to/node_modules/semver/classes/comparator.js:25:10)
at /path/to/node_modules/semver/classes/range.js:154:47
at Array.map (<anonymous>)
at Range.parseRange (/path/to/node_modules/semver/classes/range.js:154:35)
at /path/to/node_modules/semver/classes/range.js:42:22
at Array.map (<anonymous>)
at new Range (/path/to/node_modules/semver/classes/range.js:42:8)
at Object.intersects (/path/to/node_modules/semver/ranges/intersects.js:5:8)
at emit_dts (file:///path/to/@sveltejs/package/src/typescript.js:31:30)

Additional context

This appears to happen in the TypeScript declaration generation step where @sveltejs/package tries to use the semver library to parse dependency versions. Bun's catalog syntax (catalog:catalog-name) is not a valid semver range.

Current Workaround: Use explicit versions in packages that need @sveltejs/package, manually keeping them in sync with catalog definitions.

Reproduction

https://github.com/handlebauer/sveltejs-package-bun-catalog-repro

Logs

> Invalid comparator: catalog:svelte
at Comparator.parse (/path/to/node_modules/semver/classes/comparator.js:41:13)
at new Comparator (/path/to/node_modules/semver/classes/comparator.js:25:10)
at /path/to/node_modules/semver/classes/range.js:154:47
at Array.map (<anonymous>)
at Range.parseRange (/path/to/node_modules/semver/classes/range.js:154:35)
at /path/to/node_modules/semver/classes/range.js:42:22
at Array.map (<anonymous>)
at new Range (/path/to/node_modules/semver/classes/range.js:42:8)
at Object.intersects (/path/to/node_modules/semver/ranges/intersects.js:5:8)
at emit_dts (file:///path/to/@sveltejs/package/src/typescript.js:31:30)

System Info

- `@sveltejs/package`: 2.3.7
- `bun`: 1.2.14
- `node`: 20.x
- OS: macOS (Sequoia 15.3.2)

Severity

blocking an upgrade

Additional Information

https://x.com/bunjavascript/status/1925074467518353452

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions