Skip to content

[bug]: Scoped package aliases with multiple segments are truncated during import transformation #9536

@naiane-bhn

Description

@naiane-bhn

Describe the bug

When using scoped packages with multiple path segments in monorepo aliases (e.g., @package/ui/components), the shadcn CLI incorrectly truncates the alias to only the scope (e.g., @Package), causing broken imports in installed components.I intend to submit a PR for this issue. The fix involves updating the alias extraction logic in { transform-import.ts to properly detect and preserve multi-segment scoped packages.

Affected component/components

CLI - Import transformation logic

How to reproduce

Steps to reproduce:

Set up a monorepo with a scoped UI package named @company/ui (or any @scope/package format)
Configure components.json with multi-segment scoped aliases:

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

Configure tsconfig.json with corresponding paths:

json   {
     "compilerOptions": {
       "paths": {
         "@package/ui/*": ["../../packages/ui/src/*"]
       }
     }
   }

Add a component from a custom registry or shadcn:

bash pnpm dlx shadcn@latest add button

Check the generated component imports

Expected behavior:

import { Button } from "@package/ui/components/ui/button";
import { cn } from "@package/ui/lib/utils";

Actual behavior:

import { Button } from "@package/components/ui/button";
import { cn } from "@package/lib/utils";


The /ui segment is lost, breaking the imports.

### Codesandbox/StackBlitz link

_No response_

### Logs

```bash

System Info

OS: macOS 14.x
Node: v20.x
Package Manager: pnpm 9.x
shadcn CLI: latest (3.x)
Browser: N/A (CLI issue)

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions