Skip to content

Conversation

@dummdidumm
Copy link
Member

The fix in #13351 solved some issues but introduced others. This reworks the aliasing further to better check against the patterns that come up.

Fixes #13532
Fixes #13436


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:.

The fix in #13351 solved some issues but introduced others. This reworks the aliasing further to better check against the patterns that come up.

Fixes #13532
Fixes #13436
@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2025

🦋 Changeset detected

Latest commit: c6144ff

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/package 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

@svelte-docs-bot
Copy link

@Rich-Harris Rich-Harris merged commit cdc6383 into main Sep 12, 2025
22 checks passed
@Rich-Harris Rich-Harris deleted the package-alias-fix branch September 12, 2025 14:52
This was referenced Sep 12, 2025
@DePasqualeOrg
Copy link
Contributor

DePasqualeOrg commented Sep 12, 2025

After I upgraded to 2.5.1, this broke one of my Svelte packages: It left files with $lib aliases in my build directory. The affected files are shadcn-svelte components.

@dummdidumm
Copy link
Member Author

Please provide a reproduction. The Pasting the import that is left untouched should be enough

@huntabyte
Copy link
Member

@dummdidumm I'm having issues with this version of @sveltejs/package, specifically in a monorepo that I'm not experiencing with 2.5.0 where other packages inside the pnpm workspace aren't able to get types from another package.

With the following branch:
https://github.com/huntabyte/bits-ui/tree/repro-for-simon

if you run:

pnpm i && pnpm dev

and then navigate to tests/alert-dialog/alert-dialog.browser.test.ts you'll see the types aren't working and if you run pnpm check you'll see all the issues.

Downgrading to 2.5.0 fixes this.

@DePasqualeOrg
Copy link
Contributor

The problem wasn't that paths were unmodified in the build, but the opposite: A relative path like ../../Component.svelte was getting replaced with something like $lib/Component.svelte in the build.

@dummdidumm
Copy link
Member Author

@DePasqualeOrg please provide the full code of the offending file that contains the import path. I can reproduce @huntabyte's problem (export * from ... wasn't handled) but not yours. Also would be interesting to know if you have a custom alias config, because else I really can't imagine how a relative path in your original source would be replaced with a $lib in the output.

Rich-Harris pushed a commit that referenced this pull request Sep 15, 2025
* fix: handle `import/export * (as ...)` when resolving aliases

#14413 (comment)

* while we're here
@DePasqualeOrg
Copy link
Contributor

Sorry, I was wrong. The problem is in fact that this path remains unmodified in the build:

import * as Dialog from '$lib/components/ui/dialog/index.js';

I don't have any custom alias set up.

Full code of the file:

<!-- Based on https://www.shadcn-svelte.com/docs/components/dialog -->

<script lang="ts">
  import type { SubmitFunction } from '@sveltejs/kit';
  import * as Dialog from '$lib/components/ui/dialog/index.js';
  import { enhance } from '$app/forms';
  import DialogFooter from '$lib/components/dialog/DialogFooter.svelte';
  import type { Snippet } from 'svelte';

  interface Props {
    open?: boolean;
    title?: string;
    description?: string;
    message?: string;
    action?: string | null;
    loading?: boolean;
    showCancelButton?: boolean;
    confirmButtonText: string;
    confirmButtonVariant?: 'link' | 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost';
    submitFunction?: SubmitFunction | null; // For use with enhance function and form action endpoint
    handleConfirm?: (() => void) | (() => Promise<void>); // Perform action before closing dialog
    children?: Snippet;
  }

  let {
    open = $bindable(false),
    title = '',
    description = '',
    message = '',
    action = null,
    loading = false,
    showCancelButton = false,
    confirmButtonText,
    confirmButtonVariant = 'default',
    submitFunction = null,
    handleConfirm = () => {},
    children,
  }: Props = $props();

  const handleConfirmAndClose = async (event: Event): Promise<void> => {
    event.preventDefault();
    await handleConfirm();
    open = false;
  };
</script>

<Dialog.Root bind:open>
  <!-- <Dialog.Trigger>
  </Dialog.Trigger> -->
  <Dialog.Content class="rounded-lg">
    {#if title !== '' || description !== ''}
      <Dialog.Header class="gap-2 text-left">
        {#if title}
          <Dialog.Title>{title}</Dialog.Title>
        {/if}
        {#if description}
          <Dialog.Description>
            {description}
          </Dialog.Description>
        {/if}
      </Dialog.Header>
    {/if}
    {#if message}
      <div class="pb-2">{message}</div>
    {/if}
    {#if submitFunction}
      <!-- Enhanced form that sends request to form action endpoint -->
      <form use:enhance={submitFunction} {action} method={action != null ? 'post' : undefined} class="flex flex-col gap-4">
        {@render children?.()}
        <DialogFooter bind:open {loading} {showCancelButton} {confirmButtonText} {confirmButtonVariant}></DialogFooter>
      </form>
    {:else}
      <!-- Perform action and close dialog -->
      <form onsubmit={handleConfirmAndClose} class="flex flex-col gap-4">
        {@render children?.()}
        <DialogFooter bind:open {loading} {showCancelButton} {confirmButtonText} {confirmButtonVariant}></DialogFooter>
      </form>
    {/if}
  </Dialog.Content>
</Dialog.Root>

@dummdidumm
Copy link
Member Author

ok so it's the same bug as Hunta's - should be fixed in the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Path alias resolution breaks for certain paths in @sveltejs/package 2.3.8+ svelte package regression for resolving imports

5 participants