Search code examples
reactjstypescriptcreate-react-appreact-scripts

How can I get a compatible React package ecosystem having both react-scripts@x and typescript@^5?


I intend to install >= [email protected] but - as Vercel deployed - having currently [email protected], which is incompatible with typescript@5.

npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1 || ^4" from [email protected]

I can share the whole package.json with the whole ecosystem if needed.

I attempted to install other packages with --legacy-peer-deps, for example 'uuid', but the types still aren't recognized after that.


Solution

  • I think by now it is safe to say that it is almost impossible to use react-scripts with a modern setup anymore and it's becoming more and more of a security risk as well. So I would strongly recommend to move away from it.

    If you look at the create-react-app repository, you will see other people have similar issues and there has been no updates to react-scripts for more than two years now. If there had been a meaningful fix after more than 1 year of Typescript 5 being released, someone would have posted it. Even the official React docs are not recommending to use create-react-app anymore and recommend frameworks like nextJS instead (see https://react.dev/learn/start-a-new-react-project).

    Alternatively, you could also try to create a setup using vite but you will need to set up a lot of things yourself, see this quite well-written Pull Request to the new React docs: https://github.com/reactjs/react.dev/pull/6059/files. It has not been accepted yet but I still thinks it describes very well the situation and the trade-offs of using a framework like nextJS vs a more lightweight solution like viteJS.

    Long story short, if you want to use Typescript v5, I think it is safe to say you will have to move away from react-scripts. An alternative that is not really an alternative would be to wait for an official update, which no one knows when and in which shape it will come. Regarding the future of create-react-app, this most official statement I found so far from one of the create-react-app maintainers: https://github.com/reactjs/react.dev/pull/5487

    Sorry, I really do not think that there is a workaround to use Typescript v5 at the moment, and it would surprise me if there was suddenly an update because the maintainers did not mention any timeline for any rewrite of create-react-app still. If I hear about anything changing, I will happily update my answer.