create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Allow TypeScript 5+ in `peerDependencies`

Open karlhorky opened this issue 1 year ago • 10 comments

Now that TypeScript 5 was released (specifically, [email protected]), it would be great to get the restriction on the version of TypeScript removed.

Otherwise npm will throw errors like this, when resolving peer dependencies:

CodeSandbox demo (run npm i in a terminal to get the error below): https://codesandbox.io/p/sandbox/react-scripts-5-0-1-typescript-5-0-2-t48wwi

$ npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"5.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1 || ^4" from [email protected]
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"5.0.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1 || ^4" from [email protected]
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"5.0.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /project/home/karlhorky/.cache/npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /project/home/karlhorky/.cache/npm/_logs/2023-03-17T11_12_53_021Z-debug-0.log

Alternatives considered

I could instead do this if desired, which would then need to be updated again each time TypeScript 6, 7, etc are released:

-    "typescript": "^3.2.1 || ^4"
+    "typescript": "^3.2.1 || ^4 || ^5"

karlhorky avatar Mar 17 '23 09:03 karlhorky

cc @ianschmitz @iansu breaking out of the box with latest TypeScript may be enough of a reason to get a new patch release out with this change (eg. [email protected])

karlhorky avatar Mar 17 '23 10:03 karlhorky

eagerly waiting and checking everyday to see an update on this as this stops from upgrading to the latest typescript v5.0.2. Thanks

mdlkumaran avatar Mar 26 '23 15:03 mdlkumaran

Typescript does not use semantic versioning. The bump from 4.8 to 4.9 is equivalent to the bump of 4.9 to 5.0.

(The current version of Typescript was versioned as 5.0 instead of 4.10 because they never release minor releases with a numeric value greater than 9 and always bump the major version after each x.9 release)

Therefore it makes no sense to have a "^4" version restriction on Typescript.

If this project wants to play it safe, then you should maintain an explicit upper bound ("<= 4.9.*", and then moving forward change it to "<= 5.0.*", and then "<= 5.1.*", and so on, as each newly released Typescript version is tested to work).

If you don't want to play it safe then you should just have the minimal supported version (">= 3.2.1") as implemented in this PR.

The "Alternatives considered" of "^3.2.1 || ^4 || ^5" makes no sense, since future version 6.0 is no more or less likely to break things as future releases: 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8 or 5.9.

https://github.com/microsoft/TypeScript/issues/39269 https://github.com/microsoft/TypeScript/issues/14116 https://news.ycombinator.com/item?id=24224975

atanf avatar Apr 21 '23 05:04 atanf

Bumping it since it's been two months that issue persists, and a month since the last comment.

xenohunter avatar May 17 '23 20:05 xenohunter

package.json

"dependencies": {
  "react": "^18.2.0",
  "react-dom": "^18.2.0",
  "react-scripts": "5.0.1",
},
"devDependencies": {
  "@types/react": "^18.2.8",
  "@types/react-dom": "^18.2.4",
  "typescript": "^5.1.3"
},
"overrides": {
  "react-scripts": {
    "typescript": ">3.2.1"
  },
},

himyjan avatar Jun 04 '23 06:06 himyjan

It's been another quarter since the last ping here. What's stopping this from being merged? The reasoning is sound, the implementation is correct and simple.

The alternative is for people to stop using react-scripts entirely. (Or put up with the workaround above. But if a project can't merge a simple PR like this in half a year, maybe it's better not to depend on it.)

Philipp91 avatar Aug 07 '23 18:08 Philipp91

create-react-app will not be maintained any more and is effectively dead - it will be going away, replaced by a recommendation to use meta-frameworks like Next.js:

  • https://github.com/reactjs/react.dev/pull/5487#issuecomment-1409720741

karlhorky avatar Aug 07 '23 20:08 karlhorky

create-react-app will not be maintained any more and is effectively dead

I think it is a bit too premature to declare this project dead.

create-react-app is an open source project with an MIT License. If the current maintainer has decided that they will no longer work on it, then there is still a chance that someone from the community will take over maintainership. This is something that happens all the time in the open source world.

This is a popular project with lots of pull requests and community involvement, leading me to believe that there is a good chance that someone will step up and request to be an official maintainer, or will maintain their own fork that will become the new home for this project.

atanf avatar Aug 23 '23 11:08 atanf

Maybe - however, keep in mind:

  • it is pretty unmaintained since a long time now, with nobody taking on the enormous effort required
  • as noted in Dan's comment, it no longer represents the direction and features of React, so probably will not have large uptake, which will also decline over time

I would suggest taking a look at the new directions of React, which are reflected in metaframeworks like Next.js and Remix. Even if you don't go with React Server Components right away (which I can also highly recommend), you can win a lot from a modern metaframework (which create-react-app is far away from now) - first class routing, better bundling, more efficient forms of data fetching and static generation, the list goes on...

karlhorky avatar Aug 23 '23 13:08 karlhorky

please merge

tommy-gilligan avatar Jan 02 '24 03:01 tommy-gilligan

Given that there has been no commits on this codebase in pretty close to two years, it seems safe to assume that CRA is dead. The documentation also says it's not the recommended tool to start any new project.

Previous comments on this issue (and other related ones) have included a variety of ways you can override the version declaration in package.json. If you're stuck with a CRA based app, you should probably try one of those ideas (or "eject" the project and deal with all the config files yourself).

For me personally, I'm migrating my projects to Next.JS - which not only supports Typescript 5, but also all the cool stuff from React 18+. And, the ability to use Server Actions completely avoids the need to create a back end server and API (with Express or whatever) simply to serve the needs of my React front end.

craigmcc avatar Feb 01 '24 00:02 craigmcc