DEV Community

B U C H M A NšŸ’»
B U C H M A NšŸ’»

Posted on

Resolving "Error: Cannot Find Module '@babel/types'" During Shadcn-UI Installation

Introduction

Shadcn-ui is a collection of open-source reusable components designed for Next.js, Astro, Vite, etc. It features a variety of beautifully designed components that can be easily integrated into your applications. Thanks to its reusability, it's well-suited for production. The library is customizable to your preferences and accessible, ensuring versatility for users.

To incorporate Shadcn-ui components into our application, we can either install them through the CLI terminal or opt for manual installation. Utilizing the CLI terminal is easy and straightforward, making the installation process simpler compared to manual installation.

While attempting an installation using the CLI terminal, I encountered several errors. In this article, I'll guide you through troubleshooting and resolving those errors, should you encounter them as well.

How to Install Using the CLI Terminal

1. Create a project

Regardless of the application you're working on, begin by creating the project. Since we're using Next.js in this example, execute the following command:

npx create-next-app@latest my app
Enter fullscreen mode Exit fullscreen mode

2. Run the CLI init command

Once the app has been successfully created, we'll run the shadcn-ui init command to initiate the setup process for your project.

npx shadcn-ui@latest init
Enter fullscreen mode Exit fullscreen mode

After running the command, I get this error:

error: cannot find module

To address this issue, we'll replace the latest keyword in the init command with the specific version we intend to install. Since the latest version at the time of installation is 0.6.0, execute the following command:

npx shadcn-ui@0.6.0 init
Enter fullscreen mode Exit fullscreen mode

3. Configure the component.json during installation

Upon executing the command, you'll be presented with various installation options. Select those that align with your project's requirements, and the installation process will commence successfully.

Shadcn-ui installation

4. Add a component

With the installation and configuration successfully completed, we're now ready to incorporate components of our choosing, such as Card Components, Button Components, and more.

For the purposes of this article, we'll demonstrate the addition of a Button Component. To add a Button Component to your component folder, execute the following command:

npx shadcn-ui@0.6.0 add button
Enter fullscreen mode Exit fullscreen mode

This command will integrate the Button Component within a dedicated UI folder within your Component folder, enabling its utilization within your project.

To utilize this component within your project, simply import the Button Component from the Components/ui folder, and it will seamlessly display within your web page.

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

export default function Page() {
  return (
    <div className=ā€flex flex-col gap-4 items-center justify-centerā€>
      <Button>Click me</Button>
    </div>
  )
}
Enter fullscreen mode Exit fullscreen mode

On our web page, we have:

button on the web page

And that's it šŸ‘šŸ¾

Conclusion

For comprehensive guidance on leveraging other components, kindly refer to the official Shadcn-UI documentation.

With these steps, you're now equipped to effectively troubleshoot and resolve potential installation challenges that may arise with Shadcn-ui in your projects.

I sincerely hope this proves helpful.

Top comments (0)