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
73.8k stars 4.54k forks source link

[bug]: Form install (React 19/Nextjs 15) #5515

Open Natchii59 opened 2 weeks ago

Natchii59 commented 2 weeks ago

Describe the bug

Unable to install form component due to peer dependency error in React 19.

Affected component/components

Form

How to reproduce

  1. Create new Nextjs v15 project (with React 19)
  2. Init shadcn
  3. Add form component (error)

Codesandbox/StackBlitz link

No response

Logs

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: timemanager@0.1.0
npm error Found: react@19.0.0-rc-65a56d0e-20241020
npm error node_modules/react
npm error   react@"19.0.0-rc-65a56d0e-20241020" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^16.8.0 || ^17 || ^18 || ^19" from react-hook-form@7.53.1
npm error node_modules/react-hook-form
npm error   react-hook-form@"^7.53.1" from the root project
npm error   peer react-hook-form@"^7.0.0" from @hookform/resolvers@3.9.0
npm error   node_modules/@hookform/resolvers
npm error     @hookform/resolvers@"^3.9.0" 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.

System Info

macOS 15.0.1
Nodejs v20.18.0
React 19.0.0-rc-65a56d0e-20241020
Nextjs 15.0.0

Before submitting

Eldevia commented 2 weeks ago

use: npm config set legacy-peer-deps true

reynaldichernando commented 2 weeks ago

I can reproduce this, for me, I had to downgrade my React version to 18 in order for it to work.

{
    ...
    "react": "^18",
     "react-dom": "^18",
    ...
}
Natchii59 commented 2 weeks ago

I want to keep react 19.

Natchii59 commented 2 weeks ago

I set legacy-peer-deps config in .npmrc file. But now i have this...

image
reynaldichernando commented 2 weeks ago

I tried @Eldevia's solution and it also worked. You can even pass the legacy peer deps as argument for npm install. npm i --legacy-peer-deps

I guess this is mentioned in the logs explicitly

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.
Natchii59 commented 2 weeks ago

I set legacy-peer-deps config in .npmrc file. But now i have this... image

You just had to put the component in client ("use client")