How to solve dependency error in gatsby js? - reactjs

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

Related

Getting error during on "npm install recyclerlistview" in React JS project

We plan to use Flipkart/recyclerlistview in react js web application.
react#16.0.0
react-dom#16.0.0
Getting error on npm install recyclerlistview
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: digirecruiter#0.1.0
npm ERR! Found: react#16.14.0
npm ERR! node_modules/react
npm ERR! react#"^16.0.0" from the root project
npm ERR! peer react#">= 15.2.1" from recyclerlistview#4.2.0
npm ERR! node_modules/recyclerlistview
npm ERR! recyclerlistview#"" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"18.1.0" from react-native#0.70.6
npm ERR! node_modules/react-native
npm ERR! peer react-native#">= 0.30.0" from recyclerlistview#4.2.0
npm ERR! node_modules/recyclerlistview
npm ERR! recyclerlistview#"" from the root project
Does Flipkart/recyclerlistview works with react js web application?
Steps taken:
Create a ReactJS project using create-react-app
Modify package.json for react version as recyclerlistview need 16.0.0 version
"react": "^16.0.0"
"react-dom": "^16.0.0",
npm install recyclerlistview --save
Getting mentioned error

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

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

React - Error while updating from 17.0.1 to 17.0.2 [duplicate]

This question already has answers here:
What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?
(7 answers)
Closed 1 year ago.
I am getting the following error while updating from React 17.0.1 to 17.0.2.
It's not entirely clear to me why the dependencies are causing problems.
I'm using npm v 7.4.
It seems that some dependencies are incompatible with react 17. Do I understand correctly?
But npm shows e. g.
npm ERR! peer react-dom#"^15.0.0 || ^16.0.0 || ^17.0.0" from react-calendly#2.0.0
npm ERR! node_modules/react-calendly
If I think correct, React 17 should work.
Could someone explain the problem to me briefly? Is there a solution for this?
Error:
npm install --save react#17.0.2
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: react#17.0.2
npm ERR! node_modules/react
npm ERR! react#"17.0.2" from the root project
npm ERR! peer react#"^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" from mini-create-react-context#0.4.1
npm ERR! node_modules/mini-create-react-context
npm ERR! mini-create-react-context#"^0.4.0" from react-router#5.2.0
npm ERR! node_modules/react-router
npm ERR! react-router#"5.2.0" from react-router-dom#5.2.0
npm ERR! node_modules/react-router-dom
npm ERR! react-router-dom#"^5.2.0" from the root project
npm ERR! 7 more (react-calendly, react-icons, react-router, ...)
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#"^15.0.0 || ^16.0.0 || ^17.0.0" from react-calendly#2.0.0
npm ERR! node_modules/react-calendly
npm ERR! react-calendly#"^2.0.0" from the root project
npm ERR! peer react-dom#"^15.5.4 || ^16.0.0 || ^17.0.0" from react-scroll#1.8.2
npm ERR! node_modules/react-scroll
npm ERR! react-scroll#"^1.8.2" from the root project
npm ERR! 2 more (styled-components, 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!
My dependencies:
"emailjs-com": "^2.6.4",
"react": "^17.0.1",
"react-calendly": "^2.0.0",
"react-dom": "^17.0.1",
"react-icons": "^4.2.0",
"react-router-dom": "^5.2.0",
"react-router-scroll-top": "^0.2.1",
"react-scripts": "^4.0.3",
"react-scroll": "^1.8.2",
"styled-components": "^5.3.0",
"swiper": "^6.5.0"
I don't understand, why 17.0.0 should be working, but 17.0.2 not.
Thanks for your help.
You have dependency conflict which will create this problem.
I suggest solve using --force or --legacy-peer-deps.
So try :
npm install --save react#17.0.2 --force
OR
npm install --save react#17.0.2 --legacy-peer-deps
Reason of problem :
There is dependency conflict which means dependency not compatible with other or something similar which will create this problem.

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