ui: [bug]: npx shadcn-ui add calendar fails with React 19 due to react-day-picker@8.10.1 peer dependency conflict

Describe the bug

Describe the bug npx shadcn@latest add calendar fails due to React 19 compatibility issues with react-day-picker@8.10.1

Error Log

npx shadcn@latest add calendar
✔ Checking registry.
⠇ Installing dependencies.
Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

Command failed with exit code 1: npm install react-day-picker@8.10.1 date-fns @radix-ui/react-slot
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: undefined@undefined
npm error Found: react@19.1.0
npm error node_modules/react
npm error   peer react@">=16.8.0" from @floating-ui/react-dom@2.1.2
npm error   node_modules/@floating-ui/react-dom
npm error     @floating-ui/react-dom@"^2.0.0" from @radix-ui/react-popper@1.2.4
npm error     node_modules/@radix-ui/react-popover/node_modules/@radix-ui/react-popper
npm error       @radix-ui/react-popper@"1.2.4" from @radix-ui/react-popover@1.1.10
npm error       node_modules/@radix-ui/react-popover
npm error         @radix-ui/react-popover@"^1.1.10" from the root project
npm error     @floating-ui/react-dom@"^2.0.0" from @radix-ui/react-popper@1.2.2
npm error     node_modules/@radix-ui/react-popper
npm error       @radix-ui/react-popper@"1.2.2" from @radix-ui/react-menu@2.1.6
npm error       node_modules/@radix-ui/react-menu
npm error         @radix-ui/react-menu@"2.1.6" from @radix-ui/react-dropdown-menu@2.1.6
npm error         node_modules/@radix-ui/react-dropdown-menu
npm error       1 more (@radix-ui/react-tooltip)
npm error     1 more (@radix-ui/react-popper)
npm error   peer react@"^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" from @inertiajs/react@2.0.3
npm error   node_modules/@inertiajs/react
npm error     @inertiajs/react@"^2.0.3" from the root project
npm error   104 more (@radix-ui/react-alert-dialog, ...)
npm error
npm error Could not resolve dependency:
npm error react-day-picker@"8.10.1" from the root project
npm error
npm error Conflicting peer dependency: react@18.3.1
npm error node_modules/react
npm error   peer react@"^16.8.0 || ^17.0.0 || ^18.0.0" from react-day-picker@8.10.1
npm error   node_modules/react-day-picker
npm error     react-day-picker@"8.10.1" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.

### Affected component/components

Calendar

### How to reproduce

1. Fresh React 19 project
2. Run npx shadcn-ui@latest add calendar
3. See dependency conflict error

### Codesandbox/StackBlitz link

_No response_

### Logs

```bash

System Info

System: macOS
npm -v: 10.8.1
node -v: v20.16.0

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: 6
  • Comments: 16

Commits related to this issue

Most upvoted comments

Same

Image

use this for latest version

"use client";

import * as React from "react";
import { DayPicker, getDefaultClassNames } from "react-day-picker";

import { cn } from "@/lib/utils";
import { buttonVariants } from "./button";

function Calendar({
  className,
  classNames,
  showOutsideDays = true,
  ...props
}: React.ComponentProps<typeof DayPicker>) {
  const defaultClassNames = getDefaultClassNames();
  return (
    <DayPicker
      showOutsideDays={showOutsideDays}
      className={cn("p-3", className)}
      classNames={{
        months: `relative flex ${defaultClassNames.month}`,
        month_caption: `relative mx-10 flex h-7 items-center justify-center ${defaultClassNames.month_caption}`,
        weekdays: cn("flex flex-row", classNames?.weekdays),
        weekday: cn(
          "w-8 text-sm font-normal text-muted-foreground",
          classNames?.weekday
        ),
        month: cn("w-full", classNames?.month),

        caption_label: cn(
          "truncate text-sm font-medium",
          classNames?.caption_label
        ),
        button_next: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute right-1 [&_svg]:fill-foreground",
          classNames?.button_next
        ),
        button_previous: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute left-1 [&_svg]:fill-foreground",
          classNames?.button_previous
        ),
        nav: cn("flex items-start", classNames?.nav),
        month_grid: cn("mx-auto mt-4", classNames?.month_grid),
        week: cn("mt-2 flex w-max items-start", classNames?.week),
        day: cn(
          "flex size-8 flex-1 items-center justify-center p-0 text-sm",
          classNames?.day
        ),
        day_button: cn(
          "size-8 rounded-md p-0 font-normal transition-none aria-selected:opacity-100",
          classNames?.day_button
        ),
        range_start: cn(
          "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-start rounded-s-md",
          classNames?.range_start
        ),
        range_middle: cn(
          "bg-accent !text-foreground [&>button]:bg-transparent [&>button]:!text-foreground [&>button]:hover:bg-transparent [&>button]:hover:!text-foreground",
          classNames?.range_middle
        ),
        range_end: cn(
          "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-end rounded-e-md",
          classNames?.range_end
        ),
        selected: cn(
          "[&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground",
          classNames?.selected
        ),
        today: cn(
          "[&>button]:bg-accent [&>button]:text-accent-foreground",
          classNames?.today
        ),
        outside: cn(
          "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
          classNames?.outside
        ),
        disabled: cn("text-muted-foreground opacity-50", classNames?.disabled),
        hidden: cn("invisible flex-1", classNames?.hidden),
        ...classNames,
      }}
      {...props}
    />
  );
}
Calendar.displayName = "Calendar";

export { Calendar };

Hi,

I had the same issue, but after updating to the latest version it works now. I was using date-fns directly for other functions, although it’s not strictly necessary (https://daypicker.dev/changelog#whats-new)

"date-fns": "^4.1.0", "react-day-picker": "^9.6.7", "react": "19.1.0",

However, I’m now facing a small visual issue — please take a look.

Image

Thanks!

### With some style adjustments

"use client";

import * as React from "react";
import { DayPicker, getDefaultClassNames } from "react-day-picker";

import { cn } from "@/lib/utils";
import { buttonVariants } from "./button";

function Calendar({
  className,
  classNames,
  showOutsideDays = true,
  ...props
}: React.ComponentProps<typeof DayPicker>) {
  const defaultClassNames = getDefaultClassNames();
  return (
    <DayPicker
      showOutsideDays={showOutsideDays}
      className={cn("p-3", className)}
      classNames={{
        months: `relative flex ${defaultClassNames.month}`,
        month_caption: `relative mx-10 flex h-7 items-center justify-center ${defaultClassNames.month_caption}`,
        weekdays: cn("flex flex-row", classNames?.weekdays),
        weekday: cn(
          "w-8 text-sm font-normal text-muted-foreground",
          classNames?.weekday
        ),
        month: cn("w-full", classNames?.month),

        caption_label: cn(
          "truncate text-sm font-medium",
          classNames?.caption_label
        ),
        button_next: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute right-1 [&_svg]:fill-foreground",
          classNames?.button_next
        ),
        button_previous: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute left-1 [&_svg]:fill-foreground",
          classNames?.button_previous
        ),
        nav: cn("flex items-start", classNames?.nav),
        month_grid: cn("mx-auto mt-4", classNames?.month_grid),
        week: cn("mt-2 flex w-max items-start", classNames?.week),
        day: cn(
          // "flex size-8 flex-1 items-center justify-center p-0 text-sm",
          // classNames?.day

                buttonVariants({ variant: "ghost" }),
          "h-9 w-9 p-0 font-normal aria-selected:opacity-100"
        ),
        day_button: cn(
          "size-8 rounded-md p-0 font-normal transition-none aria-selected:opacity-100",
          classNames?.day_button
        ),
        range_start: cn(
          "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-start rounded-s-md",
          classNames?.range_start
        ),
        range_middle: cn(
          "bg-accent !text-foreground [&>button]:bg-transparent [&>button]:!text-foreground [&>button]:hover:bg-transparent [&>button]:hover:!text-foreground               aria-selected:bg-slate-100 aria-selected:text-slate-900 dark:aria-selected:bg-slate-800 dark:aria-selected:text-slate-50",
          classNames?.range_middle
        ),
        range_end: cn(
          "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-end rounded-e-md",
          classNames?.range_end
        ),


        // styling copied from the old calender
        selected: cn(
          "[&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground                                    bg-slate-900 text-slate-50 hover:bg-slate-900 hover:text-slate-50 focus:bg-slate-900 focus:text-slate-50 dark:bg-slate-50 dark:text-slate-900 dark:hover:bg-slate-50 dark:hover:text-slate-900 dark:focus:bg-slate-50 dark:focus:text-slate-900",
          classNames?.selected
        ),
        today : cn(

          // "[&>button]:bg-accent [&>button]:text-accent-foreground                   bg-slate-100 text-slate-900 dark:bg-slate-800 dark:text-slate-50   ",

          
                buttonVariants({ variant: "activtabe" }),
          "h-9 w-9 p-0 font-normal aria-selected:opacity-100",
          classNames?.today
        ),



        // styling copied from the old calender

        outside: cn(
          "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30                                                                                                                                                                                                                       day-outside text-slate-500 opacity-50 aria-selected:bg-slate-100/50 aria-selected:text-slate-500 aria-selected:opacity-30 dark:text-slate-400 dark:aria-selected:bg-slate-800/50 dark:aria-selected:text-slate-400",
          classNames?.outside
        ),
        disabled: cn("text-muted-foreground opacity-50", classNames?.disabled),
        hidden: cn("invisible flex-1", classNames?.hidden),
        ...classNames,
      }}
      {...props}
    />
  );
}
Calendar.displayName = "Calendar";

export { Calendar };

Same Image

use this for latest version

“use client”;

import * as React from “react”; import { DayPicker, getDefaultClassNames } from “react-day-picker”;

import { cn } from “@/lib/utils”; import { buttonVariants } from “./button”;

function Calendar({ className, classNames, showOutsideDays = true, …props }: React.ComponentProps<typeof DayPicker>) { const defaultClassNames = getDefaultClassNames(); return ( <DayPicker showOutsideDays={showOutsideDays} className={cn(“p-3”, className)} classNames={{ months: relative flex ${defaultClassNames.month}, month_caption: relative mx-10 flex h-7 items-center justify-center ${defaultClassNames.month_caption}, weekdays: cn(“flex flex-row”, classNames?.weekdays), weekday: cn( “w-8 text-sm font-normal text-muted-foreground”, classNames?.weekday ), month: cn(“w-full”, classNames?.month),

    caption_label: cn(
      "truncate text-sm font-medium",
      classNames?.caption_label
    ),
    button_next: cn(
      buttonVariants({ variant: "outline" }),
      "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute right-1 [&_svg]:fill-foreground",
      classNames?.button_next
    ),
    button_previous: cn(
      buttonVariants({ variant: "outline" }),
      "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute left-1 [&_svg]:fill-foreground",
      classNames?.button_previous
    ),
    nav: cn("flex items-start", classNames?.nav),
    month_grid: cn("mx-auto mt-4", classNames?.month_grid),
    week: cn("mt-2 flex w-max items-start", classNames?.week),
    day: cn(
      "flex size-8 flex-1 items-center justify-center p-0 text-sm",
      classNames?.day
    ),
    day_button: cn(
      "size-8 rounded-md p-0 font-normal transition-none aria-selected:opacity-100",
      classNames?.day_button
    ),
    range_start: cn(
      "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-start rounded-s-md",
      classNames?.range_start
    ),
    range_middle: cn(
      "bg-accent !text-foreground [&>button]:bg-transparent [&>button]:!text-foreground [&>button]:hover:bg-transparent [&>button]:hover:!text-foreground",
      classNames?.range_middle
    ),
    range_end: cn(
      "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-end rounded-e-md",
      classNames?.range_end
    ),
    selected: cn(
      "[&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground",
      classNames?.selected
    ),
    today: cn(
      "[&>button]:bg-accent [&>button]:text-accent-foreground",
      classNames?.today
    ),
    outside: cn(
      "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
      classNames?.outside
    ),
    disabled: cn("text-muted-foreground opacity-50", classNames?.disabled),
    hidden: cn("invisible flex-1", classNames?.hidden),
    ...classNames,
  }}
  {...props}
/>

); } Calendar.displayName = “Calendar”;

export { Calendar };

This should be updated officially. Works great, thanks.

use this

"use client";

import * as React from "react";
import { DayPicker, getDefaultClassNames } from "react-day-picker";

import { cn } from "@/lib/utils";
import { buttonVariants } from "./button";

function Calendar({
  className,
  classNames,
  showOutsideDays = true,
  ...props
}: React.ComponentProps<typeof DayPicker>) {
  const defaultClassNames = getDefaultClassNames();
  return (
    <DayPicker
      showOutsideDays={showOutsideDays}
      className={cn("p-3", className)}
      classNames={{
        months: `relative flex ${defaultClassNames.month}`,
        month_caption: `relative mx-10 flex h-7 items-center justify-center ${defaultClassNames.month_caption}`,
        weekdays: cn("flex flex-row", classNames?.weekdays),
        weekday: cn(
          "w-8 text-sm font-normal text-muted-foreground",
          classNames?.weekday
        ),
        month: cn("w-full", classNames?.month),

        caption_label: cn(
          "truncate text-sm font-medium",
          classNames?.caption_label
        ),
        button_next: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute right-1 [&_svg]:fill-foreground",
          classNames?.button_next
        ),
        button_previous: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute left-1 [&_svg]:fill-foreground",
          classNames?.button_previous
        ),
        nav: cn("flex items-start", classNames?.nav),
        month_grid: cn("mx-auto mt-4", classNames?.month_grid),
        week: cn("mt-2 flex w-max items-start", classNames?.week),
        day: cn(
          "flex size-8 flex-1 items-center justify-center p-0 text-sm",
          classNames?.day
        ),
        day_button: cn(
          "size-8 rounded-md p-0 font-normal transition-none aria-selected:opacity-100",
          classNames?.day_button
        ),
        range_start: cn(
          "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-start rounded-s-md",
          classNames?.range_start
        ),
        range_middle: cn(
          "bg-accent !text-foreground [&>button]:bg-transparent [&>button]:!text-foreground [&>button]:hover:bg-transparent [&>button]:hover:!text-foreground",
          classNames?.range_middle
        ),
        range_end: cn(
          "bg-accent [&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground day-range-end rounded-e-md",
          classNames?.range_end
        ),
        selected: cn(
          "[&>button]:bg-primary [&>button]:text-primary-foreground [&>button]:hover:bg-primary [&>button]:hover:text-primary-foreground",
          classNames?.selected
        ),
        today: cn(
          "[&>button]:bg-accent [&>button]:text-accent-foreground",
          classNames?.today
        ),
        outside: cn(
          "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
          classNames?.outside
        ),
        disabled: cn("text-muted-foreground opacity-50", classNames?.disabled),
        hidden: cn("invisible flex-1", classNames?.hidden),
        ...classNames,
      }}
      {...props}
    />
  );
}
Calendar.displayName = "Calendar";

export { Calendar };

Hi,

I had the same issue, but after updating to the latest version it works now. I was using date-fns directly for other functions, although it’s not strictly necessary (https://daypicker.dev/changelog#whats-new)

"date-fns": "^4.1.0", "react-day-picker": "^9.6.7", "react": "19.1.0",

However, I’m now facing a small visual issue — please take a look.

Image

Thanks!

Yes after updating manually it theoretically works but the problem is since react-day-picker library changed so much it corrupts the layout of the calendar. Even if you check the calendar.tsx component there are errors highlighted.

Hello @TharukaDananjaya, I would like to work on this issue.

The issue here is a compatibility issue between react 19 and the react-day-picker package (version 8.10.1) that shadcn-ui’s calendar component depends on.

If assigned this issue, I will ensure compliance with the project’s guidelines.

ETA

  • 48HRS Max

thanks for these solution