Use React 18 with Next 15
Unanswered
GetPsyched posted this in #help-forum
I bumped to Nextjs v15 with the provided codemod and it bumped React to v19 as well. I reverted this change in package.json and ran
npm i
. Running npm list react
shows React v18 but a simple console.log(React.version)
in the app shows React v19; ugh.50 Replies
I deleted anything that could possible be a cache; even
package-lock.json
; and it's still somehow getting React v19; which leads me to believe that next 15 is just doing it on its ownIrrespective of who's to blame (perhaps even my skill issue), it's really annoying that I have to fight so much to keep React 18
Asian black bear
You just can't. Next vendors React for the time being and you are forced to use React 19 RC when using Next 15.
This has been the default behavior ever since the app router came out, just that it wasn't as obvious while it was just React 18.
And no, Next 15 cannot be used with React 18, it is the minimum version required.
Next 15 cannot be used with React 19
try this
Ah, this was misleading https://discord.com/channels/752553802359505017/752647196419031042/1298612908195975239
That makes more sense
Wouldn't have wasted time fighting nextjs
I already made that fix; I just wanted to not have that problem to begin with since idk what other problems React RC would bring
Asian black bear
The docs clearly say it’s the minimum version which is expected given they vendor it. Doing any workaround is bound to cause headaches
I think he's just pointing out the typo
You meant 18*
yeah but re-read the sentence again, slowly
i know what you meant but... reread the sentence
Asian black bear
Oh yeah. Sorry.
I edited it now.
I guess I just have to wait for React 19 to be stable then
well, next 15 requires react 19 afaik so stay in next 14 for now if react 19 is not working for you
Thanks for the info guys
that said i don't think there is much problem, my website was upgraded to next 15/react 19 quite hassle-free
Yup, that's what I'm gonna do
I would make the jump for my personal stuff in a jiffy but not at my workplace :D
yeah that's a wise choice
I upgraded and still managed to keep react 18 at least that’s what it says in package json, but it clearly states that react 19 is minimum https://nextjs.org/docs/app/building-your-application/upgrading/version-15 so idk what’s happening since I’m getting next 15 features but am pretty sure react 18 is being used
Asian black bear
They are not.
Your local React version listed in package.json does not affect which version Next uses.
It only affects what auto complete and imports your IDE suggests.
Next vendors React 19 which means during runtime you will used their dedicated version of it, no matter what.
Oh that’s pretty cool, didn’t know that was possible
Thanks
Asian black bear
It's very unconventional, but by the nature of React not being stable yet and Vercel wanting to push Next they have no other way that to do that in order to bring you the new features that React 19 has. Typically they'd just declare React as a peer dependency of a specific version range and would use your local version, but this has changed at the beginning of Next 13 with the introduction of the app router and I hope they will go back to the conventional approach once React 19 is fully released.
Yh I hope they do since it feels weird to have a different version than the one set in my package json being used
But ig it’s what they have to do
When running codemod does it actually edit your code as well as installing the new versions and can it only be used when upgrading major version or does it work for example 15.0.0 to 15.0.1
Asian black bear
The codemods only do what they're programmed to do. And yes they are designed to edit your code as well, updating deprecated uses of all APIs and adjusting calls such as awaiting the new async params.
I ran
npm install react@rc react-dom@rc
but it threw me an error about how next was already using react-rc and that there was àproblem with the react 18.3.1 in my package.json so I used --force as it suggested however now all of my packages, are throwing erros like this.npm error While resolving: @stripe/react-stripe-js@2.8.1
npm error Found: react@19.0.0-rc-fb9a90fa48-20240614
npm error node_modules/react
npm error react@"^19.0.0-rc-cae764ce-20241025" from the root project
npm error peer react@"^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc" from lucide-react@0.453.0
npm error node_modules/lucide-react
npm error lucide-react@"^0.453.0" from the root project
I now have to use --force or --legacy-peer-deps, everytime I run npm install, how can I fix this
The only good way to do this is to wait until your dependencies have been updated to support react 19. Which is likely not gonna happen until after react 19 GA.
All other methods are bad one way or another, all of them are due to peer dependencies resolution failures. If you use pnpm for example, that is a warning, if you use npm that is an error unless you do force or legacy peer deps as you stated.
All other methods are bad one way or another, all of them are due to peer dependencies resolution failures. If you use pnpm for example, that is a warning, if you use npm that is an error unless you do force or legacy peer deps as you stated.
Nvm I fixed it I just downgraded back to 18.3.1, and as Near said next is still using react 19 rc under the hood
That's a really bad way of doing things, irrespective of what excuse there might be
yeah agreed very unintuitive
The entire app router relies on features not available on 18.3.1. There just Is. Not another way, that’s the only way.
Yeah, I'm not saying it shouldn't be done
Just emphasising the "evil" in necessary evil
Golden northern bumble bee
Im still confused what my react and react-dom versions should be in package json. The long v19 rc version?
cc @Asian black bear
Asian black bear
The best would be to use the currently listed version of the RC listed in the peer deps of the stable Next version you use. For example v15.0.2 lists
19.0.0-rc-02c0e824-20241028
.