Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
handlebauer opened this issue May 28, 2025 · 1 comment · Fixed by #13850
Closed
Labels
pkg:svelte-package Issues related to svelte-package

Comments

@handlebauer
Copy link

handlebauer commented May 28, 2025

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

@dummdidumm dummdidumm added the pkg:svelte-package Issues related to svelte-package label Jun 2, 2025
@dummdidumm dummdidumm assigned dummdidumm and unassigned dummdidumm Jun 2, 2025
@dummdidumm
Copy link
Member

We should adjust the code in https://github.com/sveltejs/kit/blob/main/packages/package/src/typescript.js to fall back to "no_svelte_3 : true" in case semver errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants