I am currently building out a basic nextjs website with the help of their handy typescript starter. Everything has been running smooth while developing using yarn dev until about 20 minutes ago, when I started randomly getting an error message any time I try to run yarn dev.
This is the error ouput:
It looks like you're trying to use TypeScript but do not have the required package(s) installed.
Please install @types/react by running:
yarn add --dev @types/react
This just randomly started happening with no changes made to the codebase. I've tried wiping node_modules completely and reinstalling, and even tried cleaning the yarn cache. The dependency "@types/react": "^18.0.2" is included correctly in my package.json's devDependencies object, so I am totally clueless on how to fix this.
P.S. I found an existing issue posted about this here, but it is not related to my issue at all, as it pertains to Docker. All I am doing is running next.js locally on my laptop, it is not running in production anywhere.
This appears to be an issue with the @types/react package itself, which was just updated to 18.0.2 the morning that you ran into this problem. Rolling back to 18.0.1 appears to work.
Update: This is not an issue with @types/react 18.0.4 which is used in the current create-next-app as of yesterday. Just a short term annoyance.
I had the same problem. Solved by updating Next.js and React.
Updating next.js
npm install next@latest
Updating react version in the next.js app:
npm upgrade react@latest react-dom@latest
Source: https://www.codegrepper.com/code-examples/shell/how+to+update+next+js+version
The package create-next-app has been updated!
Use: npx create-next-app@latest my-app --typescript
This works for me now ;)