Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNMET PEER DEPENDENCY with react

I'm having javascript problems related to react. This is the error caught by chrome when page is rendering:

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:

├─┬ UNMET PEER DEPENDENCY [email protected]
│ ├─┬ [email protected] 
│ │ └─┬ [email protected] 
│ │   ├── [email protected] 
│ │   ├─┬ [email protected] 
│ │   │ ├─┬ [email protected] 
...

And:

├─┬ UNMET PEER DEPENDENCY [email protected]
│ └─┬ [email protected] 
│   └─┬ [email protected] 
│     └── [email protected] 

After that I changed my package.json file to:

"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.

The VERY SAME problem continues to occur. I notice 2 warnings:

npm WARN [email protected] requires a peer of react@>=15.3 but none was installed.
npm WARN [email protected] 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?

like image 511
learner Avatar asked Apr 26 '17 14:04

learner


People also ask

What is an unmet Peer dependency?

UNMET PEER DEPENDENCY error is thrown when the dependencies of one or more modules specified in the package. json file is not met. Check the warnings carefully and update the package. json file with correct versions of dependencies.

What are peer dependencies in react?

Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package. This is useful for packages like react that need to have a single copy of react-dom that is also used by the person installing it.

How do you ignore peer dependencies?

Using --legacy-peer-deps will usually allow you to install the package without meeting the peer dependency requirements. (This was the default using npm@6 so I assume you are using npm@7 if you are seeing a problem.) If that doesn't work, --force will install without regard to peer dependencies.

How do you install peer dependencies in yarn?

Usage. Run npm install (or yarn install ) to install prod and dev , as well as peer dependencies. You still may see "unmet peer dependency" warnings, due to installation flow of npm/yarn. Also it won't update lock (shrinkwrap) files or modify package.


1 Answers

Your react version doesn't meet react-collapse requirements. 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. NPM will install latest react package. 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.

To do so type in your console npm show react-collapse versions - an array of records will show up.

Now we have to pick one earlier version and check the peerDependencies of our selected package.

We use npm view [email protected] command, the result will be

enter image description here

Because we selected @3.0.0 version which is ok in our case, we need to install it. Following command will do the work npm install --save [email protected].

UPDATE

If above solution does not work. Please install missing peerDependencies manually via npm i --save <package-name>.

Explaination:

Check your npm version doing npm -v. If your version is > 3 then it means peer dependencies must be installed manually. I guess that is the case, version 3.0.0 was released in mid 2015.

The automatic install of peer dependencies was explicitly removed with npm 3, as it cause more problems than it tried to solve.

Please read official npm changelog, you are looking for section "breaking changes".

There is CLI tool which installs an NPM package and its peer dependencies automatically. You might be interested in.

like image 111
loelsonk Avatar answered Oct 18 '22 00:10

loelsonk