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
andpackage-lock.json
and runningnpm 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.
Until this is fixed for now you can delete the
node_modules
folder andpackage-lock.json
. Next, openpackage.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):
node_modules
andpackage-lock.json
npm i web-vitals --save-dev
npm install
and then you can use
npm run build
andnpm start
again