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
62.96k stars 3.54k forks source link

[bug]: Error when running npx shadcn-ui@latest init and npx shadcn-ui@latest add button with Node.js v20.13.1 #3774

Open TanzimHossain2 opened 1 month ago

TanzimHossain2 commented 1 month ago

Describe the bug

I encountered errors when trying to run the shadcn-ui commands as described in the documentation. The commands npx shadcn-ui@latest init and npx shadcn-ui@latest add button fail with a Cannot find package error.

image

Affected component/components

shadcn/ui initialization and component addition commands.

How to reproduce

  1. Create a new Next.js project using the following command:
    npx create-next-app@latest my-app --typescript --tailwind --eslint
  2. Navigate to the project directory:
    cd my-app
  3. Run the shadcn-ui init command:
    npx shadcn-ui@latest init
  4. Alternatively, try adding a component:
    npx shadcn-ui@latest add button

Codesandbox/StackBlitz link

No response

Logs

Error message encountered:

PS C:\Users\Forhad vi\Desktop\Tanzim\LWS\Test1\my-app> npx shadcn-ui@latest init
node:internal/modules/run_main:129
    triggerUncaughtException(
    ^

Error: Cannot find package 'C:\Users\Forhad vi\AppData\Local\npm-cache\_npx\125ee17d583c4e03\node_modules\npm-run-path\node_modules\path-key\package.json' imported from C:\Users\Forhad vi\AppData\Local\npm-cache\_npx\125ee17d583c4e03\node_modules\npm-run-path\index.js
Did you mean to import "path-key/index.js"?
    at legacyMainResolve (node:internal/modules/esm/resolve:215:26)
    at packageResolve (node:internal/modules/esm/resolve:841:14)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.13.1

System Info

- Node.js: v20.13.1 (LTS version)
- Next.js: 14.2.3
- OS: Windows 11

Before submitting

basmonje commented 3 weeks ago

Hello. I had the same problem when switching node versions. In my case, I solved it by deleting the cached data stored by npx.

In the same error message, you can see the directory location that needs to be deleted in your case.

C:\Users\Forhad vi\AppData\Local\npm-cache\_npx\125ee17d583c4e03

Then, when making a new request, you need to accept the download of the library.

npx shadcn-ui@latest init
TanzimHossain2 commented 3 weeks ago

Hello. I had the same problem when switching node versions. In my case, I solved it by deleting the cached data stored by npx.

In the same error message, you can see the directory location that needs to be deleted in your case.

C:\Users\Forhad vi\AppData\Local\npm-cache\_npx\125ee17d583c4e03

Then, when making a new request, you need to accept the download of the library.

npx shadcn-ui@latest init

npx shadcn-ui init ```` remove '@latest ' part