Skip to content

Fix a 'Pre-transform error' using aliases with Vite #8

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

skirtles-code
Copy link
Owner

This fixes a problem reported in #7.

When using @ aliases with shadcn-vue, there's an error trying to run the playground and docs packages:

Pre-transform error: Failed to load url /src/lib/utils

The relevant code is:

import { cn } from '@/lib/utils'

The problem isn't unique to shadcn-vue, the same thing would happen for other uses of @ aliases that don't resolve exactly to a file. For example, any imports that don't include the extension, or that rely on resolving to an index file.

The solution implemented here is to pass the new path through this.resolve(), after the @ has been replaced. This will apply the other resolution rules required to handle those cases.

These changes should allow Vite to resolve the aliases correctly, both during dev and for a production build.

There is a related problem with the type-check command. This is still failing to resolve the aliases correctly in the playground and docs packages.

@skirtles-code skirtles-code merged commit ffe58e1 into main May 13, 2025
1 check passed
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.

1 participant