33

npx create-react-app my-project results in the following dependency errors:

npx version: 8.5.0

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"<18.0.0" from @testing-library/[email protected]
npm ERR! node_modules/@testing-library/react
npm ERR!   @testing-library/react@"^12.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.

The command still produces a project directory, but running npm start in the created directory errors with web-vitals missing from node-modules.

Solutions tried

  • Running the same command with --force or --legacy-peer-deps as suggested by the above error message doesn't solve the problem.

  • Deleting node_modules and package-lock.json and running npm i also doesn't solve the problem.

Update

The problem has been fixed with the latest update of create-react-app. Now it creates a project without any problem.

3
  • This should be fixed now. Can you still repro? Commented Apr 12, 2022 at 21:21
  • @DanAbramov Could you write an official answer please? Commented Apr 12, 2022 at 23:10
  • 1
    Update: This is not fixed. I am still facing this issue after following all the recommended practices. Commented Feb 13 at 16:17

7 Answers 7

22

Until this is fixed for now you can delete the node_modules folder and package-lock.json. Next, open package.json and change
"react": "^18.0.0" & "react-dom": "^18.0.0" to an earlier version e.g:
"react": "^17.0.2" & "react-dom": "^17.0.2".
Finally, you can run npm install.

Alternative Solution (Try this first!):
solution suggested by joooni1998):

  1. delete both node_modules and package-lock.json
  2. run npm i web-vitals --save-dev
  3. run npm install

and then you can use npm run build and npm start again

Sign up to request clarification or add additional context in comments.

7 Comments

Any idea on what's causing the underlying issue? Seems to be a webpack config. (I'm having the same issue).
I tried Gavriel's solution. The downloaded node-modules are missing web-vitals. Does someone have any idea why create-react-app can result in missing dependencies?
@DigiFreeze I think the issue is being cause by a recent merge they did to the "react-testing-library". They changed it to only supports React < 18. You can read more here & here
it didn't worked for me
@hayata_suenaga try running npm i web-vitals --save-dev if it gives out the error : 'Module not found: Error: Can't resolve 'web-vitals''
|
8

Check here for the Github issue.

Here is a temporary workaround:

  • Install cra-template to a separate folder (other than your new project app's folder) using "npm install cra-template"

  • Go to the installed cra-template package folder and in file "template.json" change the line '"@testing-library/react": "^12.0.0"' to '"@testing-library/react": "^13.0.0"'

  • Go back to your root folder and run npx create-react-app my-app (your app name) --template file:PATH_TO_YOUR_CUSTOM_TEMPLATE

Additionally, you can let the build fail, remove the node_modules folder as well as the package-json.lock file. Open the package.json file and change the react and react-dom to an earlier version.

For example:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "cra-template": "1.1.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Delete reportWebVitals.js Remove import reportWebVitals from './reportWebVitals'; from index.js Remove reportWebVitals(); from the bottom of index.js

Finally run npm install

3 Comments

Thank you! Can confirm this works for the typescript template (the name of the package is cra-template-typescript). I didn't have to remove reportWebVitals either.
I wanted to take the custom templating approach but when I run "npm install cra-template" in a different directory I get the following message "up to date, audited 4 packages in 1s" but nothing is installed in that directory. There is no template.json to modify. Any pointers on this would be really appreciated.
react, react-dom, @testing-library/react - which of the mentioned packages is the culprit?
3

It worked for me by deleting both 'node_modules' folder and 'package-lock.json' file. Then, I changed both react and react-dom version to 17.0.2 instead of 18.0.0 inside the package.json file as suggested by Gavriel's answer https://stackoverflow.com/a/71836018/12490294. Then, inside the app folder, I ran

    npm i web-vitals --save-dev

Then

    npm start

The app started successfully

Comments

1

Or you can try this npx --legacy-peer-deps create-react-app my-appname or goto index.js and remove the usage of web vitals

or downgrade npm with npm install -g [email protected] and create react app.

Comments

1

You could use yarn add create-react-app your-app instead

Comments

0

Been over a year since this was asked, and in spite of the suggestion by OP that it's been fixed in new versions of create-react-app, it still hasn't been. Also, downgrading react in package.json didn't work. Had to take the risk and run the command with --legacy-peer-deps before I could get my app working.

Comments

-2

Try running either with --force or with --legacy-peer-deps, both will install dependencies without problems.

If that doesn't work, then delete the node modules folder and start installing from scratch

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.