ui icon indicating copy to clipboard operation
ui copied to clipboard

Issue while using shadcn-ui with React CRA

Open SUMANTH-hyphen opened this issue 1 year ago • 3 comments

I'm trying to use a shadcn-ui component in my react app using CRA with typescript and tailwind CSS. Below i have added the primary parts of the code.

tailwind.config.js content: [ './pages/**/*.{ts,tsx}', './components/**/*.{ts,tsx}', './app/**/*.{ts,tsx}', './src/**/*.{ts,tsx}', ],

tsconfig.json [{ "baseUrl": ".", "paths": { "@/*": ["./src/*"] } }, "include": [ "src", "**/*.ts", "**/*.tsx" ]

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": "slate", "cssVariables": true, "prefix": "" }, "aliases": { "components": "@/components", "utils": "@/lib/utils" } }

usage import { Button } from '@/components/ui/button'

Here is the folder structure Screenshot 2023-12-27 at 3 35 48 PM

Error Module not found: Error: Can't resolve '@/components/ui/button'

SUMANTH-hyphen avatar Dec 27 '23 10:12 SUMANTH-hyphen

Use Path in tsconfig.json "paths": { "@/*": ["./src/*"] }

7hourspg avatar Dec 27 '23 12:12 7hourspg

Use Path in tsconfig.json "paths": { "@/*": ["./src/*"] }

I've used it, please check the code I provided

SUMANTH-hyphen avatar Dec 27 '23 12:12 SUMANTH-hyphen

You'd need to install and setup tsconfig paths with craco. Which means you'll have to eject your create-react-app setup. Personally, I'd advise you use Vite instead. Then you won't have this problem

princemuel avatar Dec 27 '23 15:12 princemuel

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 26 '24 23:02 shadcn