gpt4 book ai didi

Could not resolve dependency error peer react@"^16.8.0 || ^17.0.0" from @material-ui/[email protected](无法从@MATERIAL-UI/[电子邮件受保护]解析依赖项错误对等反应@“^16.8.0|^17.0.0”)

转载 作者:bug小助手 更新时间:2023-10-25 13:38:20 27 4
gpt4 key购买 nike



While trying to install npm install, I am getting below error, how to resolve it?

尝试安装NPM Install时,出现以下错误,如何解决?


$

$


npm install
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@"^16.8.0 || ^17.0.0" from @material-ui/[email protected]
npm ERR! node_modules/@material-ui/core
npm ERR! @material-ui/core@"^4.12.4" 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

//Package.json


{
"name": "sssclub",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@material-ui/core": "^4.12.4",
"@mui/icons-material": "^5.8.3",
"@mui/material": "^5.8.3",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"cors": "^2.8.5",
"express": "^4.18.1",
"multer": "^1.4.4",
"mysql2": "^2.3.3",
"path": "^0.12.7",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-hook-form": "^7.31.2",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-tweet-embed": "^2.0.0",
"sequelize": "^6.20.1",
"web-vitals": "^2.1.4"
},
"engines": {
"node": "16.14.2",
"npm": "8.5.0"
},
"proxy": "http://localhost:8000",
"scripts": {
"start": "react-scripts start",
"start:server": "node src/server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"preinstall": "npx npm-force-resolutions"
},
"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"
]
}
}

更多回答

Obey packages semver unless you have a really good reason not to. Downgrade react (easy) to upgrade material ui (hard)

一定要遵守包装,除非你有很好的理由不这样做。降级反应(轻松)升级材料用户界面(硬)

@AdamJenkins Could you explain in more detail or make an answer for those of us who hit this error while just getting started with React? I get that you're saying it is easier to downgrade React than to upgrade Material UI, but it makes no sense to me how to do either or why. And by semver did you mean semantic version? Typo? Something else?

@AdamJenkins,你能更详细地解释一下,或者为我们这些在刚刚开始使用Reaction时遇到这个错误的人做出回答吗?我明白你的意思,降级Reaction比升级材料用户界面更容易,但这对我来说没有任何意义,无论是怎么做,为什么。你指的是语义版吗?打字错误?还有别的事吗?

优秀答案推荐

Try this

尝尝这个


npm config set legacy-peer-deps true
npm i


Instead of npm install, please use npm install --legacy-peer-deps.

请不要使用NPM安装,而是使用NPM Install--Legacy-Peer-deps。



Above all solutions are true. Here I will explain a solution to why we need to set legacy-peer-deps in the app.

最重要的是,所有的解决方案都是正确的。在这里,我将解释为什么我们需要在应用程序中设置遗留同行代表的解决方案。


The concept of peer dependencies can cause challenges when installing packages. Consider the following scenario:

对等依赖关系的概念可能会在安装包时带来挑战。请考虑以下场景:


Package A requires Package B, and both have a common peer dependency, Package C. However, Package A requires Package C in version 1.x, while Package B requires Package C in version 2.x.

包A需要包B,两者都有一个共同的对等依赖项,包C。然而,包A需要1.x版的包C,而包B需要2.x版的包C。


When you try to install Package A and Package B together in your project, npm might encounter a conflict due to the different peer dependency versions required by each package. This can lead to installation failures, and it becomes challenging to resolve the conflicts manually.

当您尝试在项目中同时安装包A和包B时,由于每个包所需的对等依赖版本不同,NPM可能会遇到冲突。这可能会导致安装失败,手动解决冲突变得具有挑战性。


"npm config set legacy-peer-deps true"

“npm config set legacy-peer-deps true”


To alleviate the complications caused by conflicting peer dependencies, npm introduced the "legacy-peer-deps" configuration flag. When set to true, this flag instructs npm to revert to the older behavior of installing packages with peer dependencies.

为了减少由相互冲突的对等依赖关系引起的复杂性,NPM引入了“Legacy-Peer-Deps”配置标志。当设置为True时,此标志指示NPM恢复到安装具有对等依赖项的包的旧行为。


The "legacy-peer-deps" flag works as follows:

“Legacy-Peer-Deps”标志的工作方式如下:


If a package declares a peer dependency, npm will install the specified version without verifying if it satisfies the version range expected by the dependent package.

如果程序包声明了对等依赖关系,则NPM将安装指定的版本,而不验证它是否满足依赖程序包预期的版本范围。


The flag disables the strict version checking for peer dependencies, making it more permissive during the installation process.

该标志禁用对对等依赖项的严格版本检查,使其在安装过程中更具容许性。


Usage and Example

用法和示例


To set the "legacy-peer-deps" flag to true, open your terminal and run the following commands:

要将“Legacy-Peer-deps”标志设置为True,请打开您的终端并运行以下命令:


npm config set legacy-peer-deps true
npm install


Delete the node_modules folder and try this following command

删除NODE_MODULES文件夹并尝试执行以下命令


npm config set legacy-peer-deps true
npm install


Mine worked using:

我的工作方式是:


npm i @testing-library/react-native@latest react-test-renderer --save --legacy-peer-deps


I had this error with Heroku deployment. So no matter what code you change, it will never run on your hosting server if this is the error. I had the same issue and after trying every fix, I realized the solution was just to delete my entire Heroku app and then recreate the app and upload the older code (Last commit that worked). Heroku and other deployment servers keep caches and settings which become way too far gone and corrupt once they encounter a horrific piece of new code which makes the server crash indefinitely.

我在部署Heroku时遇到了这个错误。因此,无论您更改什么代码,如果这是错误,它将永远不会在您的托管服务器上运行。我遇到了同样的问题,在尝试了所有修复程序后,我意识到解决方案就是删除我的整个Heroku应用程序,然后重新创建应用程序并上传较旧的代码(上次提交有效)。Heroku和其他部署服务器保留着缓存和设置,一旦它们遇到一段可怕的新代码,这些缓存和设置就会变得太远,并且会损坏,从而使服务器无限崩溃。


You have to just delete your entire app on the server and start a completely brand new app based on the last commit where your code was last working/running on the server. (You should be able to maintain the same name.)

你必须删除服务器上的整个应用程序,并根据你的代码在服务器上最后一次工作/运行的最后一次提交启动一个全新的应用程序。(You应该能够保持相同的名称)。


But there is some type of horrible mine in your recent commit which caused the entire server to remain crashed forever until it's destruction and recreation most likely.

但在您最近的提交中有某种可怕的地雷,导致整个服务器永远崩溃,直到它最有可能被破坏和重新启动。


Most likely the cause are some comments that the server is unable to ignore as your local is able to ignore.
Delete all comments and try to reload your code again on a NEW SERVER INSTANCE. Comments that use {/* are extremely unfriendly compared to comments with //

最有可能的原因是服务器无法忽略一些备注,因为您的本地用户能够忽略这些备注。删除所有注释,并尝试在新的服务器实例上重新加载代码。与使用//的评论相比,使用{/*的评论非常不友好


Another extremely unfriendly piece of code are older html shortcut tags such as  

另一段非常不友好的代码是较旧的html快捷标记,如


A final case would be to remove unnecessary lifecycle methods.

最后一种情况是删除不必要的生命周期方法。


But the most important thing here is to completely destroy your server instance and start over with code which doesn't completely corrupt your server forever due to some line of recent code.

但这里最重要的事情是完全销毁您的服务器实例,并从不会因为最近的代码行而永久地完全损坏您的服务器的代码重新开始。


At least this was my case with Heroku.

至少这是我和Heroku的案子。


(Also, Using Websites such as Digital Ocean for hosting tend to give you better error messages which has helped me in the past to realize errors sooner, although it might be a little more costly.)

(此外,使用Digital Ocean等网站进行托管往往会给你提供更好的错误信息,这在过去帮助我更快地意识到错误,尽管它可能会稍微贵一点。)



I solved it this way in my app folder:

我在我的应用文件夹中这样解决了这个问题:


C:\Users\Me\App> npm i react-speech-kit --legacy-peer-deps


Best way is to use YARN instead of NPM. Delete the node_modules folder and install dependencies using yarn. Run command yarn and it will resolve dependencies itself.
install yarn as global package if its not installed using command npm install -g yarn

最好的方法是用纱线代替NPM。删除NODE_MODULES文件夹,并使用YAIN安装依赖项。运行COMMAND YING,它将自动解析依赖项。如果未使用命令npm install-g yer安装全局包,则将其安装为全局包



You could also use npm install --force, it did work for me but I believe that npm config set legacy-peer-deps true will also work. See which works best :D

您也可以使用NPM Install--force,它确实对我起作用,但我相信NPM配置设置Legacy-Peer-deps true也会起作用。看看哪个效果最好:D



Delete complete node_modules => folder
Run command...

删除完整节点模块=>文件夹运行命令...


npm install

NPM安装


更多回答

Do i need to remove package-lock.json, node_modules first and then install it ?

我是否需要先删除Package-lock.json,NODE_MODULES,然后再安装?

first try it directly if it doesn't works than remove.

如果不起作用,首先直接试一试,然后取下。

Ok Sure, will try and reply back

好的,当然,我会尽量回复的

Installation is successfull but Now I am getting this error... Plugin "react" was conflicted between "package.json » eslint-config-react-app » C:\Proj\work\sss\node_modules\eslint-config-react-app\base.js" and "BaseConfig » C:\Proj\Work\sss\node_modules\eslint-config-react-app\base.js".

安装成功,但现在我收到此错误...插件“Reaction”在“Package.json?eslint-CONFIG-REACT-APP?C:\Proj\work\sss\node_modules\eslint-config-react-app\base.js”和“BaseConfiger?C:\Proj\Work\sss\node_modules\eslint-config-react-app\base.js”.之间冲突

Check this out stackoverflow.com/questions/70377211/…

请访问Stackoverflow.com/Questions/70377211/…

explanation? documentation?

解释?文档?

does it safe to do it in production?

在生产中这样做安全吗?

very well explained @rizwan

很好地解释了@里兹万

This answer is what solved it for me.

这个答案为我解决了这个问题。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com