Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unable to resolve dependency in Create React App Typescript template #2128

Closed
strican opened this issue Nov 5, 2020 · 8 comments
Closed
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release

Comments

@strican
Copy link

strican commented Nov 5, 2020

Current Behavior:

Based off the feedback in #2000, I'm filing a unique bug on this. In an empty React Applicaiton created with the create-react-app Typescript template, npm install fails with the following:

$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: typescript@4.0.5
npm ERR! node_modules/typescript
npm ERR!   typescript@"^4.0.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1" from react-scripts@4.0.0
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"4.0.0" 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.

Expected Behavior:

npm install should succeed

Steps To Reproduce:

npx create-react-app myapp --template typescript
cd myapp
rm -rf node_modules
npm install

Environment:

  • OS: MacOS 10.15.6
  • Node: 15.1.0
  • npm: 7.0.8
@strican strican added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Nov 5, 2020
@ljharb
Copy link
Collaborator

ljharb commented Nov 5, 2020

This version of react-scripts requires typescript 3, and you’re using typescript 4. To make your dep graph valid, you’ll have to downgrade typescript, or upgrade to a version of react-scripts that allows typescript 4, if it exists.

@strican
Copy link
Author

strican commented Nov 5, 2020

Is this a bug with Create React App then? The install works with Yarn though. Is NPM being stricter about dependencies than other package managers?

@ljharb
Copy link
Collaborator

ljharb commented Nov 5, 2020

No, it’s a bug with your package.json, since that’s what declares typescript. However, if CRA is generating that, then yes, it’s a bug in CRA.

npm 7 properly checks peer deps on install (altho it unfortunately doesn’t fail by default when there’s a peer dep issue like this), and i don’t believe any other npm package CLIs do.

@strican
Copy link
Author

strican commented Nov 5, 2020

Thanks for the explanation. Looks like this was filed as facebook/create-react-app#9995.

@ljharb
Copy link
Collaborator

ljharb commented Nov 5, 2020

facebook/create-react-app#9964 seems like it will fix it, once merged and released. Closing this in favor of the linked issue and PR.

@lalberto8085
Copy link

Hello I know it's been a while, what version was this fixed on?

@ljharb
Copy link
Collaborator

ljharb commented Jan 18, 2021

@lalberto8085 no version of npm; if you click on the CRA PR, and on the commit that merged it, you'll see it's not released there yet.

@SurajJadhav7
Copy link

This issue is still present.

My Environments:

OS: MacOS 11.2.3
Node: 15.12.0
npm: 7.6.3

I was able to resolve it by downgrading typescript version in package.json

"devDependencies": {
    "@babel/runtime": "7.13.8",
    "typescript": "3.2.1"
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

5 participants