Cannot run NPM install because it's 'unable to resolve dependency tree' - node.js

I had some issues with my node_modules so I went to delete the node_modules and run npm install. Boy was that a mistake. My project is completely messed up. When I run npm install npm it sends back this:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project#0.1.0
npm ERR! Found: react#17.0.2
npm ERR! node_modules/react
npm ERR! react#"^17.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"15.3.0 - 16.x" from react-vis#1.11.7
npm ERR! node_modules/react-vis
npm ERR! react-vis#"^1.11.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 /Users/Cole/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Cole/.npm/_logs/2021-05-26T10_34_07_786Z-debug.log
Someone please help me!
Edit: Here is my package.json.
{
"name": "project",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.12.0",
"#testing-library/react": "^11.2.6",
"#testing-library/user-event": "^12.8.3",
"axios": "^0.21.1",
"npm": "^7.14.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
"react-vis": "^1.11.7",
"redux": "^4.1.0",
"web-vitals": "^1.1.1"
},
"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"
]
}
}
Not quite sure what I did that was so detrimental but this has been a painful experience.
When running npm audit it shows that there are 87 vulnerabilities.
Running npm audit fix and npm audit fix --force do not fix anything.
Is there a way to refresh all the node_modules? Go back to square one and re-install all dependencies again?

Seems like react-vis has a peer dependency of react#"15.3.0 - 16.x". Since you have react#17.0.2, it complains. Try changing
"react": "^17.0.2",
"react-dom": "^17.0.2",
to
"react": "^16.14.0",
"react-dom": "^16.14.0",

Related

Upgrading to react 18 results in package dependencies errors

I have the following package.json file:
{
"name": "web",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emotion/react": "^11.10.0",
"#emotion/styled": "^11.10.0",
"#fontsource/roboto": "^4.5.7",
"#mui/icons-material": "^5.8.4",
"#mui/lab": "^5.0.0-alpha.93",
"#mui/material": "^5.9.3",
"#reduxjs/toolkit": "^1.8.3",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"animate.css": "^4.1.1",
"generate-password-browser": "^1.1.0",
"notistack": "^2.0.5",
"query-string": "^7.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"string-to-color": "^2.2.2",
"stylis-plugin-rtl": "^2.1.1",
"traverse": "^0.6.6",
"typed.js": "^2.0.12",
"web-vitals": "^2.1.4"
},
"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"
]
}
}
I have created this project using create-react-app just now, so everything is clean and new, I have only installed additional packages.
Now, I want to install the following package:
react-swipeable-views
Which had over 260,000 downloads this week,
$ npm i react-swipeable-views
and I'm getting this error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: web#0.1.0
npm ERR! Found: react#18.2.0
npm ERR! node_modules/react
npm ERR! react#"^18.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^15.3.0 || ^16.0.0 || ^17.0.0" from react-swipeable-views#0.14.0
npm ERR! node_modules/react-swipeable-views
npm ERR! react-swipeable-views#"*" 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/sam/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/sam/.npm/_logs/2022-08-04T16_50_51_600Z-debug-0.log
Everything was working just fine before the idea of moving to react 18.
Thanks react, now how do I fix this problem? I have tens of other dependencies which I'm unable to install because of this error, I was able to rescue the ones listed above in the package.json file, thank god.
If I wanted to roll back to react#17 I can't because there's no way you can do it since create-react-app does not have such an option, and if you npm un react and npm i react#17 the errors will remain because create-react-app installs other dependencies and not only react.
Any help to get out of this problem?
with explanation, why this is happening if possible 🌹.
npm ERR! peer react#"^15.3.0 || ^16.0.0 || ^17.0.0" from react-swipeable-views#0.14.0
That library doesn't support anything in 18 yet. According to the project github the issue was opened already this year.

Error Could not resolve dependency: redux-react-session

I need to install this package https://www.npmjs.com/package/redux-react-session
installing it with npm npm i redux-react-session shows this error:
PS C:\Users\michael\Desktop\login and signup\client> npm i redux-react-session
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: client#0.1.0
npm ERR! Found: react#18.1.0
npm ERR! node_modules/react
npm ERR! react#"^18.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^0.14.0 || ^15.0.0 || ^16.0.0" from redux-react-session#2.6.1
npm ERR! node_modules/redux-react-session
npm ERR! redux-react-session#"*" 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.
package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emotion/react": "^11.9.0",
"#emotion/styled": "^11.8.1",
"#mui/material": "^5.8.0",
"#mui/styled-engine-sc": "^5.8.0",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.2.0",
"#testing-library/user-event": "^13.5.0",
"antd": "^4.20.5",
"axios": "^0.27.2",
"formik": "^2.2.9",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "^4.4.0",
"react-loader-spinner": "^5.1.5",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"redux-thunk": "^2.4.1",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"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"
]
}
}
when installing npm packages?
There are two solutions to resolve this issue. Let us look at each of those in detail.
Solution 1: Ignore the peerDependencies
The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.
Try the below command to install the dependencies for your project.
npm install --save --legacy-peer-deps
You can also set this permanently by adding this into a configuration by running the below command.
npm config set legacy-peer-deps true
Note: In this solution, the peer dependencies will not be installed by default, even if you are using the latest version of NPM.
Solution 2: Using –force
The other solution is to use the --force flag. The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk.
Step 1: Delete the current node_modules. You can remove it by using the below command.
rm -rf node_modules
Step 2: Remove the package-lock.json by running the below command
rm package-lock.json
Step 3: Clear the npm cache and perform the clean installation with --force flag as shown below.
npm cache clean --force
npm install --force
By performing the above steps, you should resolve the issue successfully.

I can't solve the dependency tree every time i try to install #craco/craco

Unable to solve dependency tree trying to install tailwind.
This is my package.json:
{
"name": "front-end",
"version": "0.1.0",
"private": true,
"devDependencies": {
"autoprefixer": "^9.8.8",
"eslint": "^8.15.0",
"jest": "^28.1.0",
"postcss": "^7.0.39",
"tailwindcss": "npm:#tailwindcss/postcss7-compat#^2.2.17"
},
"dependencies": {
"#craco/craco": "^6.4.3",
"#testing-library/jest-dom": "^5.16.1",
"#testing-library/react": "^12.1.2",
"#testing-library/user-event": "^13.5.0",
"axios": "^0.25.0",
"js-cookie": "^3.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.1",
"react-scripts": "5.0.0",
"redux": "^4.1.2",
"redux-devtools-extension": "^2.13.9",
"redux-saga": "^1.1.3",
"router": "^1.3.6",
"web-vitals": "^2.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "jest",
"lint": "eslint .",
"lint:fix": "eslint --fix --ext .js,.jsx ."
},
"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"
]
}
}
This is what I see in my console:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: front-end#0.1.0
npm ERR! Found: react-scripts#5.0.0
npm ERR! node_modules/react-scripts
npm ERR! react-scripts#"5.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-scripts#"^4.0.0" from #craco/craco#6.4.3
npm ERR! node_modules/#craco/craco
npm ERR! #craco/craco#"^6.4.3" 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\Tejas\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\Tejas\AppData\Local\npm-cache\_logs\2022-05-14T14_36_01_226Z-debug-0.log
i am trying to configure tailwind css and to override reactcss i am trying install #craco/craco but i am getting this error i tried useing
npm install --save --legacy-peer-deps
and installed craco using this
npm install #craco/craco --save --legacy-peer-deps
but after that it is giving me error
Downgrade the version of react-script from 5.0.0 to 4.0.0

Conflicts in React dependency tree

When running the react app I got this error in console - SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.
Based on StackOverflow's suggestions I tried updating react version. I had version 16 and switched to 17. But now there are conflicts in the dependency tree. When I try to npm install this is the error I'm getting:
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#">=16.8.0" from #emotion/react#11.1.5
npm ERR! node_modules/#emotion/react
npm ERR! #emotion/react#"^11.1.1" from react-select#4.3.0
npm ERR! node_modules/react-select
npm ERR! react-select#"^4.2.1" from the root project
npm ERR! 17 more (#material-ui/core, #material-ui/lab, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^0.14 || ^15.0.0 || ^16.0.0-alpha" from airbnb-prop-types#2.160
npm ERR! node_modules/airbnb-prop-types
npm ERR! airbnb-prop-types#"^2.16.0" from enzyme-adapter-utils#1.14.0
npm ERR! node_modules/enzyme-adapter-utils
npm ERR! enzyme-adapter-utils#"^1.14.0" from enzyme-adapter-react-16#1.15.6
npm ERR! node_modules/enzyme-adapter-react-16
npm ERR! dev enzyme-adapter-react-16#"^1.15.6" 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 rport.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Local\npm-cache\_logs\2021-04-25T15_17_39_361Z-dbug.log
package.json :
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.11.3",
"#material-ui/lab": "^4.0.0-alpha.57",
"#testing-library/jest-dom": "^5.11.9",
"#testing-library/react": "^11.2.5",
"#testing-library/user-event": "^12.8.3",
"aos": "^2.3.4",
"react": "^17.0.2",
"react-dom": "^17.0.1",
"react-icons": "^4.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-select": "^4.2.1",
"react-spring": "^8.0.27",
"styled-components": "^5.2.1",
"web-vitals": "^1.1.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"
]
},
"devDependencies": {
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"jest": "^26.6.0",
"react-dev-utils": "^11.0.4"
},
"proxy": "http://localhost:8080"
}
As I understand the error occurs because of the version of the enzyme. I tried upgrading it to version 17, but react doesn't let me do it and I get the above-given error.
What could be the solution to resolve the dependency conflicts?
I had the same issue, so I've installed the dependencies with yarn. and it worked like magic.
If you have React version 17, you can use this unofficial adapter for React 17 for enzyme.
import { configure } from 'enzyme';
import Adapter from '#wojtekmaj/enzyme-adapter-react-17';
configure({ adapter: new Adapter() });
Your package.json file contains the declaration of which version of React you're using. As long as your project is has all it needs from the version of React that enzyme-adapter-react-16 requires - which is ^16.4.0-0 according to Justin Mitchell - you can use that.
"dependencies": {
...
"react": "^16.4.0-0",
"react-dom": "^16.4.0-0",
...
}

Node.js 15 dependency problem with pullstate 1.20.x

i want to use pullstate.js in my react project but it seems to be impossible to use it with the Node.js 15.
I have tried it in Node.js 13 and there it works. Can Anybody help?
In this example i created a plain react app and try to add the dependency.
package,json
``
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#popperjs/core": "^2.9.0",
"#testing-library/jest-dom": "^5.11.9",
"#testing-library/react": "^11.2.5",
"#testing-library/user-event": "^12.8.1",
"ajv": "^6.12.6",
"bootstrap": "^4.5.3",
"moment": "^2.29.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.0",
"pullstate":"1.20.1"
},
"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"
]
}
}
``
This ist the rror i get after npm install.
code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-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.12.0" from pullstate#1.20.1
npm ERR! node_modules/pullstate
npm ERR! pullstate#"1.20.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.
This is unfortunately due to NPM version 7 being way more strict about peer dependency mismatches.
To get the old behaviour, run npm install with --legacy-peer-deps, as they say in the error message.
I've just released Pullstate version 1.21.0 - this has set a more broad peer dependency for React, including ^1.17.0 - I think this should solve this issue.

Resources