Skip to content
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

[bug]: CLI not respecting settings in components.json #6386

Open
2 tasks done
nathanburgess opened this issue Jan 17, 2025 · 3 comments · May be fixed by #6443
Open
2 tasks done

[bug]: CLI not respecting settings in components.json #6386

nathanburgess opened this issue Jan 17, 2025 · 3 comments · May be fixed by #6443
Labels
bug Something isn't working

Comments

@nathanburgess
Copy link

nathanburgess commented Jan 17, 2025

Describe the bug

{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "rsc": false,
  "tsx": true,
  "tailwind": {
    "config": "tailwind.config.ts",
    "css": "app/app.css",
    "baseColor": "zinc",
    "cssVariables": true,
    "prefix": "",
    "tsx": true
  },
  "aliases": {
    "components": "~/app/components",
    "utils": "~/app/utilities",
    "ui": "~/app/components/ui",
    "lib": "~/app/utilities",
    "hooks": "~/app/hooks"
  },
  "iconLibrary": "lucide"
}

I have this for my components.json and whenever I install a new component the import for cn is always import { cn } from "~/lib/utils"

Affected component/components

CLI

How to reproduce

  1. Install shadcn
  2. Modify components.json with a new utils alias
  3. Install any component (i.e.: pnpm dlx shadcn@latest add checkbox)
  4. Open the checkbox and see that the config wasn't respected

Codesandbox/StackBlitz link

No response

Logs

System Info

MacOS, Vite, React Router 7

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@nathanburgess nathanburgess added the bug Something isn't working label Jan 17, 2025
@ander-rentcars
Copy link

I'm having the same problem with turbopack design-system example. Could be a pnpm issue?

My components.json aliases:

"aliases": {
        "components": "@acme/ui/components",
        "utils": "@acme/ui/lib/utils",
        "hooks": "@acme/ui/hooks",
        "lib": "@acme/ui/lib",
        "ui": "@acme/ui/components"
    },

@dan5py
Copy link
Contributor

dan5py commented Jan 24, 2025

It's not an pnpm issue. I've been experiencing this problem in my repo turborepo-shadcn-ui too.

The issue is within the transform-import.ts file.
It seems like that when transforming non-registry imports like @/lib/utils it uses this snippet to replace the alias:

// Not a registry import.
if (!moduleSpecifier.startsWith("@/registry/")) {
// We fix the alias and return.
const alias = config.aliases.components.split("/")[0]
return moduleSpecifier.replace(/^@\//, `${alias}/`)
}

So in this case the "utils" alias is not being used.

@dan5py dan5py linked a pull request Jan 24, 2025 that will close this issue
@dan5py
Copy link
Contributor

dan5py commented Jan 24, 2025

This PR should fix the issue without breaking other configs.
@shadcn this is quite important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants