简体   繁体   English

未满足的对等依赖与反应

[英]UNMET PEER DEPENDENCY with react

I'm having javascript problems related to react.我遇到了与反应相关的 javascript 问题。 This is the error caught by chrome when page is rendering:这是页面渲染时 chrome 捕获的错误:

Uncaught TypeError: Super expression must either be null or a function, not undefined
at _inherits (application.js:16301)
at application.js:16310
at Object.232.prop-types (application.js:16549)
at s (application.js:1)
at application.js:1
at Object.233../Collapse (application.js:16574)
at s (application.js:1)
at application.js:1
at Object.1.react (application.js:78)
at s (application.js:1)

When I've install my react using npm it complains about peer dependencies of react and react-height:当我使用 npm 安装我的反应时,它抱怨反应和反应高度的对等依赖性:

├─┬ UNMET PEER DEPENDENCY react@0.14.9
│ ├─┬ envify@3.4.1 
│ │ └─┬ jstransform@11.0.3 
│ │   ├── base62@1.1.2 
│ │   ├─┬ commoner@0.10.8 
│ │   │ ├─┬ commander@2.9.0 
...

And:和:

├─┬ UNMET PEER DEPENDENCY react-height@2.2.1
│ └─┬ create-react-class@15.5.2 
│   └─┬ fbjs@0.8.12 
│     └── core-js@1.2.7 

After that I changed my package.json file to:之后,我将 package.json 文件更改为:

"react": "0.14.9",
"react-bootstrap": "^0.28.1",
"react-collapse": "^2.2.1",
"react-dom": "^0.14.3",
"react-height": "2.2.1",
...

After these changes I removed completely node_modules folder with rm -rf did an npm cache clean and reinstall again.在这些更改之后,我使用rm -rf完全删除了node_modules文件夹,清理了 npm 缓存并再次重新安装。

The VERY SAME problem continues to occur.非常相同的问题继续发生。 I notice 2 warnings:我注意到 2 个警告:

npm WARN react-collapse@2.4.0 requires a peer of react@>=15.3 but none was installed.
npm WARN react-collapse@2.4.0 requires a peer of react-height@^3 but none was installed.

Is there a problem to update the packages or a problem related to react itself?更新包有问题还是反应本身有问题?

Your react version doesn't meet react-collapse requirements. 您的react版本不符合react-collapse要求。 It doesn't really mean that both packages can't work together, just try it and if everything works as intended. 这并不意味着两个软件包不能一起工作,只是试一试,如果一切都按预期工作。

But if you need to fix that you have two ways of doing that: 但是如果你需要修复它,你有两种方法:

First way 第一种方式

Delete "react": "0.14.9", line, and run npm i --save react . 删除"react": "0.14.9",行,并运行npm i --save react NPM will install latest react package. NPM将安装最新的反应包。 Error should be fixed. 错误应该修复。


Second way 第二种方式

If you really need to use 0.14.9 version you should find react-collapse version which is compatible with your reactjs version. 如果你真的需要使用0.14.9版本,你应该找到与你的reactjs版本兼容的react-collapse版本。

To do so type in your console npm show react-collapse versions - an array of records will show up. 为此,请在控制台中输入npm show react-collapse versions - 将显示array记录。

Now we have to pick one earlier version and check the peerDependencies of our selected package. 现在我们必须选择一个早期版本并检查所选包的peerDependencies

We use npm view react-collapse@3.0.0 command, the result will be 我们使用npm view react-collapse@3.0.0命令,结果将是

在此输入图像描述

Because we selected @3.0.0 version which is ok in our case, we need to install it. 因为我们在我们的案例中选择了@3.0.0版本,我们需要安装它。 Following command will do the work npm install --save react-collapse@3.0.0 . 以下命令将执行npm install --save react-collapse@3.0.0的工作。

UPDATE UPDATE

If above solution does not work. 如果以上解决方案不起作用。 Please install missing peerDependencies manually via npm i --save <package-name> . 请通过npm i --save <package-name>手动安装缺少的peerDependencies。

Explaination: 阐释:

Check your npm version doing npm -v . 检查你的npm版本做npm -v If your version is > 3 then it means peer dependencies must be installed manually. 如果您的版本大于3,则表示必须手动安装对等依赖项。 I guess that is the case, version 3.0.0 was released in mid 2015. 我想是这样的,版本3.0.0在2015年中期发布。

The automatic install of peer dependencies was explicitly removed with npm 3, as it cause more problems than it tried to solve. 使用npm 3显式删除了对等依赖项的自动安装,因为它会导致比尝试解决的问题更多的问题。

Please read official npm changelog , you are looking for section "breaking changes". 请阅读官方的npm更改日志 ,您正在寻找“突破性更改”部分。

There is CLI tool which installs an NPM package and its peer dependencies automatically. 有一个CLI工具可以自动安装NPM包及其对等依赖项。 You might be interested in. 你可能感兴趣。

Make sure you have a package.lock.json file in your directory.确保您的目录中有package.lock.json文件。 React uses yarn command, instead of trying npm install try doing yarn add <package name> React 使用 yarn 命令,而不是尝试 npm install 尝试做yarn add <package name>

I had the same peer dependency error during netlify build and deploy with my react-elastic-carousel and the only thing that solved it was.在使用我的 react-elastic-carousel 构建和部署 netlify 期间,我遇到了相同的对等依赖错误,唯一解决它的是。

yarn add react-elastic-carousel

Hope it helps!希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM