ui: Project initialization puts folder in incorrect place
Hi there, just initialized a project, and for some reason, my whole tailwind custom theme breaks when using shadcn UI. Here is my configuration file
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/styles/globals.css",
"baseColor": "gray",
"cssVariables": false
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
Also project structure,
--| components.json
--| tailwind.config.js
--| src
----| styles
------| globals.css
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 33 (3 by maintainers)
I’ve been having the same issue. I was running:
$ npx shadcn-ui@latest initand when using
Configure the import alias for components: › @/componentsit created an@folder in my root directory.My solution was:
In my project root, I opened the
tsconfig.jsonand found that my"paths"key was set differently thanshadcnexpected. I corrected it to:and now it’s working.
I solved the issue doing this changes in tsconfig.json file
this work for me now 😊😊
I’ve had the same issue, and after struggling for 1 hour, this is what works for me.
My folder structure looks like this:
| public | src -> | app -> | components | component.json | (other cofig files)
changes made in the
tsconfig.jsonfile:I ran into this issue too where the CLI tool creates an
@/directory… Thetsconfig.jsonlooks likeUsing Next.js 12 if that helps
The new tsconfig files generated by vite (e.g. when I did
pnpm create vite) outputs a different tsconfig layout, and it looks like the CLI doesn’t handle it properly.For a quicker workaround, you could just use my tsconfig from an open source project:
tsconfig.app.jsonnpx shadcn-ui@latest initI found a simpler solution than my original one,
pathstotsconfig.json’scompilerOptions, so that the shadcn ui tool will find thecompilerOptions.pathsand output it’s code to the right folder (instead of the@in the root):tsconfig.app.json, so that our code can also import from@. This is required because some of the code from shadcn has@imports to:npx shadcn-ui@latest add buttonnpx shadcn-ui@latest add buttonWithout debugging/reading the shadcn code, I believe the shadcn init tool is expecting to read tsconfig.json’s
compilerOptions.paths, but it’s no longer there. See https://github.com/shadcn-ui/ui/issues/797#issuecomment-2198316058 for more infoEven if your component paths in tsconfig contains “@/components/“: [”./components/”], you still need to add “@/“: [”./”]. That should solve your issue.
I’m having the same issue, tried everything in the comments and nothing works. If I configure the aliases as “src/components” it works, but if I configure as “@/components” it creates de @ folder at the base level of my project.
Don’t work:
Works:
My tsconfig files:
tsconfig.json
tsconfig.app.json
tsconfig.node.json
vite.config.js
components.js
tailwind.config.ts
Can someone spot the problem? FYI I’m using WSL
For me its working for both tsconfig.json OR jsconfig.json
{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./src/*"] } } }Unfortunately, that’s not the outcome I’m expecting. My configuration in
tsconfig.jsonlooks like this:This configuration correctly places
lib/utils(forcn) in./src. I expected the same behavior for components. However, due to the current alias/path configuration, the components alias doesn’t seem to map correctly incomponents.json. The files are being created in the root directory, even though we have a specific path set for components intsconfig.json.Therefore, the issue appears in the alias mapping in
components.json. The alias for@/componentsdoesn’t map with@/components/*as it should. Instead, it seems to only map with@/components. I’m considering adding the following to mytsconfig.json:Thank you!! @forhadmia1
Adding compilerOptions to tsconfig.json instead of tsconfig.app.json worked for me too.
This is not ideal. It would be better if we could just have one alias to match whatever TSConfig path.
I have a lot of paths:
Organizing my repo.
Did you add the paths in the
tsconfig.json?