Open vanirvan opened 2 months ago
What exactly is going wrong? Is the CLI not picking up your new utils file path?
@imMatheus
I guess the button.ts
still contains import { cn } from "~/lib/utils"
instead of import { cn } from "~/lib/utils/cn"
.
What exactly is going wrong? Is the CLI not picking up your new utils file path?
Yes, sorry for not replying as soon as possible, the button component is importing the utils.ts
file from ~/lib/utils
not cn.ts
file from ~lib/utils/cn
.
Expected Output:
...
import { cn } from "~/lib/utils/cn";
// the rest of button component
Intead of :
...
import { cn } from "~/lib/utils";
// the rest of button component
@vanirvan I am not a maintainer or contributor to this project, but I ran into this on my own project and did some investigation/testing and it seems as though the issue is that you're using something other than @
as the start of your path alias for the components key in your components.json. To confirm, temporarily change your components key to @/components and give a try to npx shadcn@latest add button
(or any other component) and I suspect it will then respect your custom path alias to the utils. I'm fairly certain this is a bug in the new shadcn
cli because trying with the old cli (aka npx shadcn-ui@0.8.0 add button
) seems to just take the value of the utils alias verbatim and doesn't try to do any calculation to determine the correct path to use for the utils file.
I'll take a look.
@vanirvan I am not a maintainer or contributor to this project, but I ran into this on my own project and did some investigation/testing and it seems as though the issue is that you're using something other than
@
as the start of your path alias for the components key in your components.json. To confirm, temporarily change your components key to @/components and give a try tonpx shadcn@latest add button
(or any other component) and I suspect it will then respect your custom path alias to the utils. I'm fairly certain this is a bug in the newshadcn
cli because trying with the old cli (akanpx shadcn-ui@0.8.0 add button
) seems to just take the value of the utils alias verbatim and doesn't try to do any calculation to determine the correct path to use for the utils file.
@andrewbrey Hello sir, sorry for not replying as soon as possible, and seems like your advice is indeed works, i changed the path alias from ~/app
into @/app
and it works very well, thankyou, maybe the downside is i only need change the path alias. But i hope in the future, shadcn-ui team would fix this.
once again, thank you
I encountered the same problem This worked before but it seems something was broken.
Seeing this issue also. It likely may be due to this related bug: https://github.com/shadcn-ui/ui/issues/5433#issuecomment-2425131609
I'm encountering same issue. lib
or utils
config aliases seems to be ignored.
Describe the bug
when adding a new components for example
npx shadcn@latest add button
. usually the components importing the generated "utils" file, however, i rename the file to "cn.ts" and move it from~/lib/utils
to~/lib/utils/cn
. I also change the generatedcomponents.json
file and refer the moved utils file to correct path.here's my
components.json
file:also my
tsconfig.json
file (i'm not changing anything):I do the same thing when working with Nextjs project, and everything works fine, but in Remix, this happened.
Affected component/components
Probably all components, but i only try it on Button, Label, and Form
How to reproduce
lib
folder namedutils
utils.ts
to insideutils
folderutils.ts
intocn.ts
components.json
, replace"utils": "~/lib/utils",
to"utils": "~/lib/utils/cn",
npx shadcn@latest add button
button.ts
cannot find module ~/lib/utils
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
Before submitting