shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
70.83k stars 4.26k forks source link

[bug]: Init creates `@` folder instead of alias for /components and /lib/utils.ts #3411

Open T04435 opened 5 months ago

T04435 commented 5 months ago

Describe the bug

When using the init command leaving everything with defaults the output of the aliases is a folder @/components/ui @/lib/utils.ts

Instead we should get ~/components/ui ~/lib/utils.ts

Think the issue here: https://github.com/shadcn-ui/ui/blob/7590fb76364c46b72653623b6ee4a96f0ad0bca8/packages/cli/src/commands/init.ts#L327

when @/components/ui and @/lib are provided it creates the @/ folder.

Affected component/components

ALL

How to reproduce

  1. pnpm dlx shadcn-ui@latest init
  2. All defaults
  3. Created folders @/components/ui & @lib/utils
Screenshot 2024-04-07 at 11 52 30 PM Screenshot 2024-04-07 at 11 52 48 PM Screenshot 2024-04-07 at 11 55 57 PM

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

macOS: Sonoma 14.4.1 (23E224)

Before submitting

T04435 commented 5 months ago

same happens if the path provided is ~/components/ui it creates a folder ~/

Screenshot 2024-04-08 at 12 13 42 AM
randriamanampisoastone commented 5 months ago

I too encountered the same problem. it took me a lot of time.

Did you find a solution?

ceednee commented 5 months ago

+1

servesh-chaturvedi commented 5 months ago

@T04435 could you share your tsconfig.json file?

kmccrory-grx commented 5 months ago

+1000 Here. Im using in a monorepo and having it create these folders on init is really messing with our config. It would also be great if i could separate the install folder from the import alias.

elijahmontenegro commented 4 months ago

I think I might be onto something. I fixed the issue for my situation so hopefully this info helps. I am using a turborepo monorepo, trying to generate shaycn-ui components in a packages/ui project. The issue seems to be with how typescript configurations operate against a baseUrl property.

I was extending packages/configs/typescript/base.json in my packages/ui/tsconfig.json. The configuration was added as a dependency in my project @repo/configs. I was hoping to inherit the setting for "baseUrl": "." that way, but Typescript saw this and used the relative path according to where the template file was located, at least I think so.

The result was a @repo/configs folder getting generated containing the shaycn-ui output, much like you guys reported but with an @ folder being made instead.

To fix it, I took the "baseUrl" property out of my base configuration template and moved it to my project. Upon running npx shadcn-ui@latest init it correctly generated the files in my src folder.

vasvalstan commented 3 months ago

Same issue here, no idea how to get over it...

LTOpen commented 3 months ago

Same issue, I reinit shadcn but the problem still exists. tsconfig.json

{
  "compilerOptions": {
    "composite": true,
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    },

components.json

{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "default",
  "rsc": false,
  "tsx": true,
  "tailwind": {
    "config": "tailwind.config.js",
    "css": "src/index.css",
    "baseColor": "neutral",
    "cssVariables": true,
    "prefix": ""
  },
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils"
  }
}
Ankur1493 commented 3 weeks ago

did anyone find the solution to this?

lukjaki commented 3 weeks ago

Same issue for me :|