ui: [bug]:Error: Cannot read properties of undefined (reading 'resolvedPaths')

Describe the bug

I’m encountering an error when trying to install the pagination component from ShadCN into my Next.js project. The error message is: Cannot read properties of undefined (reading ‘resolvedPaths’). This issue occurs when I attempt to integrate the pagination component, preventing the installation from completing successfully.

Steps to Reproduce: To reproduce the issue, I created a new Next.js project (or opened an existing one), and then tried installing the ShadCN pagination component. When running the installation command, the error message appeared.

Expected Behavior: The pagination component should install without any issues and be functional in the Next.js project.

Actual Behavior: The installation fails with the error message: Cannot read properties of undefined (reading ‘resolvedPaths’).

Image

Affected component/components

Page

How to reproduce

To reproduce the issue, I created a new Next.js project (or opened an existing one), and then tried installing the ShadCN pagination component. When running the installation command, the error message appeared.

Codesandbox/StackBlitz link

No response

Logs

The error message is: Cannot read properties of undefined (reading 'resolvedPaths').

System Info

Terminal

Before submitting

  • I’ve made research efforts and searched the documentation
  • I’ve searched for existing issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 64
  • Comments: 22

Most upvoted comments

Hello, try the following, I believe it will work.

Delete your components.json file. Run npx shadcn@latest init. Then try adding a component as a test.

Try doing this in a copy of your project. This worked for me.

Got this same error when installing the toast.

npx shadcn@latest add toast

Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

Cannot read properties of undefined (reading 'resolvedPaths')

Shadcn himself says this is the fix https://github.com/shadcn-ui/ui/issues/6527#issue-2823569500

You need to have aliases defined for these 5 things in the components.json file. Nuking it and installing again adds, these, but you don’t have to you can just add them.

“aliases”: { “components”: “@/components”, “utils”: “@/lib/utils”, “ui”: “@/components/ui”, “lib”: “@/lib”, “hooks”: “@/hooks” }

✅ OK

npx shadcn@2.1.8 add dialog

❌ NG

npx shadcn@latest add dialog

Me too, I got the same error when adding the slider component from Shadcn CLI and fixed it as mentioned in the following solution, thanks!

Hello, try the following, I believe it will work.

Delete your components.json file. Run npx shadcn@latest init. Then try adding a component as a test.

Try doing this in a copy of your project. This worked for me.

I believe the above will work in most cases but if not, try these steps:

# 1. Remove existing shadcn installation
npm uninstall shadcn-ui

# 2. Clear npm cache
npm cache clean --force

# 3. Install shadcn CLI globally
npm install -g shadcn-ui

# 4. Remove `components.json` file from your project
rm ./components.json

# 5. Initialize shadcn in your project
npx shadcn@latest init

# 6. Now try adding a Shadcn component
npx shadcn@latest add <Shadcn Component Name>

Got this same error when installing the toast.

npx shadcn@latest add toast

Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

Cannot read properties of undefined (reading 'resolvedPaths')

Shadcn himself says this is the fix #6527 (comment)

You need to have aliases defined for these 5 things in the components.json file. Nuking it and installing again adds, these, but you don’t have to you can just add them.

“aliases”: { “components”: “@/components”, “utils”: “@/lib/utils”, “ui”: “@/components/ui”, “lib”: “@/lib”, “hooks”: “@/hooks” }

This solution should be the correct answer

Hello, try the following, I believe it will work.

Delete your components.json file. Run npx shadcn@latest init. Then try adding a component as a test.

Try doing this in a copy of your project. This worked for me.

This worked for me. THX @jhonypdev

The Solution of giving a npx shadcn@latest init updates the code, but be careful if you have styling variables, try just giving the command and copying your variables and putting them again, otherwise it will reset everything!

Same issue - just FYI for the team:

When trying to add dropdown using npm

Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

Cannot read properties of undefined (reading 'resolvedPaths')