when using create-react-app dependencies #testing-library could not resolve - reactjs

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: learn#0.1.0
npm ERR! Found: react#18.0.0
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/react#12.1.5
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.
npm ERR!
npm ERR! See C:\Users\user\AppData\Local\npm-cache\eresolve-report.txt for a full report.
When I used npm start it gives this error:
Compiled with problems:
ERROR in ./src/reportWebVitals.js 5:4-24
Module not found: Error: Can't resolve 'web-vitals' in 'D:\React\Education\Fetch api\my-learn\src'
I tried with clear cache,
deleting node modules and then again installing them (npm install),
Then changed from package.json to this:
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, run npm install.
None of the solutions worked for me. How can I solve this?

From
React JS npm start shows failed to compile web-vitals
Basically run
npm i web-vitals --save-dev
on your terminal and it should work.

You will need to update #testing-library/react to the latest version to use it properly with React 18.
Run the command:
npm i #testing-library/react#13.0.1
Tested on my project where I had the same problem

Related

Error occured while creating a react app and unable to start the react app

I am newbie to react technology and I faced an error while creating a react app:
Initialized a git repository.
Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: frontend#0.1.0
npm ERR! Found: react#18.0.0
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/react#12.1.5
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.
npm ERR!
npm ERR! See C:\Users\nahee\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\nahee\AppData\Local\npm-cache\_logs\2022-04-12T12_46_13_743Z-debug-0.log
`npm install --no-audit --save #testing-library/jest-dom#^5.14.1 #testing-library/react#^12.0.0 #testing-library/user-event#^13.2.1 web-vitals#^2.1.0` failed
As a result I am unable to start the app
For this I used npm uninstall -g create-react-app and npm cache verify commands to clear the error even though I am unable to resolve it.
For creating a react app I used
npx create-react-app frontend
What is my issue?
I think there is an issue with react-testing-library. Based on the error message, it supports only React < 18 version. You can read it here.
For an alternative solutions, you can manually add those to your project like how they mentioned on the error log(which I did for myself)
npm install --no-audit --save #testing-library/jest-dom#^5.14.1 #testing-library/react#^12.0.0 #testing-library/user-event#^13.2.1 web-vitals#^2.1.0` failed
Or you can check this too.
create-react-app dependency version issues with React 18

Issues Installing Vue-Native with library vue-native-scripts

I am trying to create a project with Vue-Native following the instructions in the documentation:
https://vue-native.io/docs/installation.html
I am trying it with Expo and Vue-React, and in both cases I have the same error when I run "npm start":
Failed to construct transformer: Error: Cannot find module 'vue-native-scripts'
I try to install it with npm install vue-native-scripts --save-dev and I have the error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: vuenativetest#0.0.1
npm ERR! Found: react#16.13.1
npm ERR! node_modules/react
npm ERR! react#"16.13.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"17.0.1" from react-native#0.64.0
npm ERR! node_modules/react-native
npm ERR! react-native#"^0.64.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.
npm ERR!
npm ERR! See /home/miguel/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/miguel/.npm/_logs/2021-04-04T10_52_07_169Z-debug.log
I updated all libraries: React, React-Native, npm, Node, etc.
But I have the same error.
I am currently working on a vue-native project and encountered this problem when I started.
This seems to be a problem about the dependencies of a vue-native project having sub dependencies of different versions from other dependencies. When NPM sees this it just freaks out.
My solution is to start using yarn! Install it by the following:
$ npm i -g yarn
After its installed, its advised that you delete the project and redo the vue-native-cli init command so it can use yarn from there, but you can also just directly use the following command without deleting the project:
$ yarn install vue-native-scripts

How to solve dependency error in gatsby js?

I was following Gatsbyjs tutorial. (https://www.gatsbyjs.com/docs/tutorial/part-four/) Link here.
I typed the command in window terminal,
gatsby new tutorial-part-four https://github.com/gatsbyjs/gatsby-starter-hello-world
cd tutorial-part-four
npm install gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion #emotion/react
But error has occurred with these messages,
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: gatsby-starter-hello-world#0.1.0
npm ERR! Found: react#17.0.1
npm ERR! node_modules/react
npm ERR! react#"^17.0.1" from the root project
npm ERR! peer react#"^16.9.0 || ^17.0.0" from gatsby-plugin-typography#3.0.0
npm ERR! node_modules/gatsby-plugin-typography
npm ERR! gatsby-plugin-typography#"*" from the root project
npm ERR! 2 more (gatsby, react-dom)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^0.14.0 || ^15.0.0 || ^16.0.0" from react-typography#0.16.19
npm ERR! node_modules/react-typography
npm ERR! peer react-typography#"^0.16.1 || ^1.0.0-alpha.0" from gatsby-plugin-typography#3.0.0
npm ERR! node_modules/gatsby-plugin-typography
npm ERR! gatsby-plugin-typography#"*" 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 C:\Users\pc\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\pc\AppData\Local\npm-cache\_logs\2021-03-13T09_43_09_116Z-debug.log
I want to know how to solve these error?
react-typography isn't ready for react 17, so you'll have to downgrade react into version 16 to use it.
Edit package.json and look for:
"dependencies": {
...
"react": "^17.0.1",
"react-dom": "^17.0.1",
...
},
change the version numbers to 16.14.0
"dependencies": {
...
"react": "^16.14.0",
"react-dom": "^16.14.0",
...
},
Save it and then remove all the files from node_modules/
rm -Rf node_modules
Finally, just reinstall everything using the command:
npm install
Continue with your command...
npm install gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion #emotion/react
I think the error is coming from npm versions
Try with adding --legacy-peer-deps option in npm install command
npm install gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion #emotion/react --legacy-peer-deps
or try after cleaning the npm by using below command
npm cache clean --force

npm peer dependencies for react-helmet-async package gives error using React 17

For a React 17 project, bootstrapped with create-react-app, I want to use the react-helmet-async package.
This project has the following peer dependencies, located in the package.json file:
"peerDependencies": {
"react": "^16.6.0",
"react-dom": "^16.6.0"
},
When trying to install the package, the following error appears:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project#1.0.0
npm ERR! Found: react#17.0.1
npm ERR! node_modules/react
npm ERR! react#"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.6.0" from react-helmet-async#1.0.7
npm ERR! node_modules/react-helmet-async
npm ERR! react-helmet-async#"^1.0.7" 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 /home/bas/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/bas/.npm/_logs/2021-02-11T13_55_56_813Z-debug.log
As far as I understand, the react-helmet-async package requires React ^16.6.0 for projects using this package. I can use the --force option, which removes the error, but when I try to do an npm update it keeps recurring.
I tried adding resolutions in my package.json, trying to force the package to use the React version I'm using. Before running a npm install or npm update, I ran npx npm-force-resolutions.
"resolutions": {
"react-helmet-async/react": "^17.0.1"
}
This unfortuntaly did not work. Is there any way, without downgrading to React 16, to still use this package without receiving errors in my console? Also, am I misunderstanding something about peer dependencies?
As far as the peer dependency of react#^16 I ran out of luck other then using the --force option when installing the package. However a commit in a new version of react-helmet-async fixed the problem.

Unable to install FluentUI packages for react app

I started learning React and FluentUI 2 hours back. I am trying out various tutorials available over internet but cannot just get through the FluentUI package installation step. I get the below error:
npm i #fluentui/react
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: fluent-ui-todo-app#0.1.0
npm ERR! Found: react#17.0.1
npm ERR! node_modules/react
npm ERR! react#"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#">=16.8.0 <17.0.0" from #fluentui/react#7.153.4
npm ERR! node_modules/#fluentui/react
npm ERR! #fluentui/react#"*" 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 ------\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! ------\Local\npm-cache\_logs\2020-12-10T12_41_32_759Z-debug.log
I tried uninstalling react and installing react#16.14.0, but that doesn't help because there are other packages that depend on react#17.0.1. What can I do?
npm install react#16.14.0
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: react#16.14.0
npm ERR! node_modules/react
npm ERR! react#"16.14.0" from the root project
npm ERR! peer react#"*" from #testing-library/react#11.2.2
npm ERR! node_modules/#testing-library/react
npm ERR! #testing-library/react#"^11.2.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"17.0.1" from react-dom#17.0.1
npm ERR! node_modules/react-dom
npm ERR! peer react-dom#"*" from #testing-library/react#11.2.2
npm ERR! node_modules/#testing-library/react
npm ERR! #testing-library/react#"^11.2.2" from the root project
npm ERR! react-dom#"^17.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!
I had same issue when trying to install fluentui package and after some trial/error loop I found that it works for me with react version 16.8 and I had to change following packages:
"#types/react": "16.8",
"#types/react-dom": "16.8",
"react": "16.8",
"react-dom": "16.8"
Hope this helps, cheers ;)
Microsoft Fluent-ui peer dependencies doesn't support React version 18. You got to wait for the package release or downgrade your application to version 16. Change your package.json.
"#types/react": "16.8",
"#types/react-dom": "16.8",
"react": "16.8",
"react-dom": "16.8"

Resources