npm peerDependency - can't install package

2019-02-26 20:10发布

问题:

I'm new to npm world, so maybe it's easy. The problem is the following:

I have a project with installed react v.15.2.0, and I need to install a package, e.g. react typist - https://github.com/jstejada/react-typist. When I do it, I gen an error: (npm v2.*)

npm ERR! peerinvalid The package react@15.2.1 does not satisfy its siblings' peerDependencies requirements!

Reading on the internet, I followed an advice to update npm itself to v.3, so I did it by running npm install -g npm. But the error is still there:

+-- UNMET PEER DEPENDENCY react@15.2.1

I assume, that I need to update react to v.15.2.1, but don't know how to do it. Running npm update doesn't help, still same error. Could you please advice, how to solve the issue?

Thanks.

回答1:

The version message is the other way around to what you're thinking. It's saying "the version of react that you have is 15.2.1 and that doesn't match what react-typist needs".

Indeed if you look in the react typist package.json you'll see that they require version 0.14 of React. That's the problem. Looks like the repo hasn't been touched for almost a year, so you might want to pick something else, or fork it and make some changes.



回答2:

EDIT: If you want to update your npm package, you should do the following.

On your package.json file look for the line:

"react": "^15.2.0",

change the version number 15.2.0 to 15.2.1 and run npm install. It'll update your react to 15.2.1.

But the main detail you should have included in your question is the following warning:

react-typist@0.3.0 requires a peer of react@^0.14 but none was installed.

The recommended method is the one David Gilbertson suggested:

Indeed if you look in the react typist package.json you'll see that they require version 0.14 of React. That's the problem. Looks like the repo hasn't been touched for almost a year, so you might want to pick something else, or fork it and make some changes.

If you really want to use this component and function properly, you'll have to downgrade to react 0.14, which isn't recommended.

To downgrade use: npm install --save react@^0.14