ui icon indicating copy to clipboard operation
ui copied to clipboard

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

Open sharathone23 opened this issue 2 years ago • 1 comments

I am using expo react-native and followed the installation steps listed here https://ui.shadcn.com/docs/installation. Not sure what I am missing here.

AssetRegistry.js:13 Uncaught Error: Cannot find module '@/components/ui/accordion' at webpackMissingModule (AssetRegistry.js:13:1) at ./src/components/Dashboard.jsx (AssetRegistry.js:13:1) at webpack_require (bootstrap:24:1) at fn (hot module replacement:62:1) at ./App.js (bundle.js:19:83) at webpack_require (bootstrap:24:1) at fn (hot module replacement:62:1) at ./node_modules/expo/AppEntry.js (WebBrowser.types.ts:192:1) at webpack_require (bootstrap:24:1) at startup:6:1

sharathone23 avatar Jun 06 '23 02:06 sharathone23

Under the hood, react native renders mobile native components that you would have used while coding in the native language on the platform.

https://reactnative.dev/docs/libraries#determining-library-compatibility

ghost avatar Jun 06 '23 13:06 ghost

I am getting same error for Next.js I followed https://ui.shadcn.com/docs/installation/next

MarkiyanPyts avatar Jul 20 '23 11:07 MarkiyanPyts

Same here. Followed the steps.

cloudders-cloud avatar Jul 23 '23 07:07 cloudders-cloud

@MarkiyanPyts @cloudders-cloud I meet a similar error as well following the nextjs doc, turns out there's a typo in the doc, I bring a PR to fix that part https://github.com/shadcn-ui/ui/pull/1027

you need to import button component this way

import { Button } from "@/components/ui/button"

timqian avatar Jul 25 '23 08:07 timqian

Fixed in #1062

shadcn avatar Aug 03 '23 18:08 shadcn

S

@MarkiyanPyts @cloudders-cloud I meet a similar error as well following the nextjs doc, turns out there's a typo in the doc, I bring a PR to fix that part #1027

you need to import button component this way

import { Button } from "@/components/ui/button"

Same issue still exist

abdou6666 avatar Sep 15 '23 17:09 abdou6666

You might end up here if, like me, you're trying to set up path redirection in tsconfig.json, but your app is setup with Create React App.

In that case, you can't configure the proper path redirections because of how it configures Webpack. So to solve this, you need to rewire it someone and override its webpack config. Here is how:

https://plusreturn.com/blog/how-to-configure-a-path-alias-in-a-react-typescript-app-for-cleaner-imports/

usr-ein avatar Dec 25 '23 21:12 usr-ein

Why is the shadcn community okay with such a vague import path that is problematic out of the box?

import { Button } from "@/components/ui/button"

from @/components looks like a very bad naming convention

For the sake of everyone's sanity, just use a modern standard naming convention for imports like

import { Button } from "@shadcn-ui/components/ui/button"

I'm just trying to follow the tutorial for installing shadcn to render a button in a blank app and I'm running into this import issue: Cannot find module '@/components/ui/button' or its corresponding type declarations.ts(2307)

I'm not using webpack, just a simple Vite react app and this is problematic.

Why does this need to be overly complicated?

vallamost avatar Jul 07 '24 20:07 vallamost

Why is the shadcn community okay with such a vague import path that is problematic out of the box?

import { Button } from "@/components/ui/button"

from @/components looks like a very bad naming convention

For the sake of everyone's sanity, just use a modern standard naming convention for imports like

import { Button } from "@shadcn-ui/components/ui/button"

I'm just trying to follow the tutorial for installing shadcn to render a button in a blank app and I'm running into this import issue: Cannot find module '@/components/ui/button' or its corresponding type declarations.ts(2307)

I'm not using webpack, just a simple Vite react app and this is problematic.

Why does this need to be overly complicated?

I have the same problem, is over complicated to get a simple button in a page.

gara501 avatar Jul 08 '24 16:07 gara501

I cannot get this to work

kevincompton avatar Jul 10 '24 23:07 kevincompton

I cannot get this to work

I finally have a solution.

First, change the reference in json file (components.json) from @ to components. Second, run again npx shadcn-ui@latest init the menu will ask again some options, answer in the same way as the first time. Now the reference should be working well, components will be in /components/ui, if fails, just check the PATH inside the component used to Utils file.

gara501 avatar Jul 11 '24 05:07 gara501

@kevincompton and everyone who is having this issue:

You need to add components manually using npx shadcn-ui@latest add COMPONENTNAME

Some examples: npx shadcn-ui@latest add textarea or npx shadcn-ui@latest add button

FreshImmuc avatar Jul 15 '24 14:07 FreshImmuc