You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

安装react-html-parser时遭遇ERESOLVE依赖树解析失败问题的解决方案求助

Fixing ERESOLVE Dependency Conflict for react-html-parser

Hey there, let's break down and fix this issue you're facing!

What's causing the error?

The core problem here is a peer dependency mismatch:

  • Your project uses React ^17.0.2
  • The version of react-html-parser you're trying to install (v2.0.2) only lists React ^0.14.0 || ^15.0.0 || ^16.0.0-0 as supported peer dependencies.

Starting with npm v7, npm enforces strict peer dependency resolution by default, which is why you're seeing the ERESOLVE unable to resolve dependency tree error.

Solutions to try

1. Use --legacy-peer-deps (Quickest Fix)

This flag tells npm to use the older peer dependency resolution logic from npm v6, which ignores strict version mismatches. This works because many older packages are actually compatible with newer React versions even if their peer dependencies aren't updated.

Run this command instead:

npm install react-html-parser --legacy-peer-deps

After installation, start your project and check if everything works. If there are no runtime errors, you're good to go!

2. Install a newer version of react-html-parser (if available)

It's possible that a newer version of react-html-parser has updated its peer dependencies to support React 17. First, check all available versions:

npm show react-html-parser versions

If you see a version higher than 2.0.2, try installing the latest one:

npm install react-html-parser@latest

3. Downgrade React to 16.x (Last Resort)

If the above options don't work, you can downgrade your React version to match the peer dependency requirement. Note that this might cause conflicts with other packages in your project (like react-scripts@5.0.0 which supports React 17), so test thoroughly after:

npm install react@^16.14.0 react-dom@^16.14.0

4. Switch to a maintained alternative

If react-html-parser seems unmaintained, consider using html-react-parser—a more actively updated package that supports React 17+ out of the box:

npm install html-react-parser

Final Notes

Most of the time, option 1 (--legacy-peer-deps) will resolve the issue without any side effects. If you run into runtime errors after installation, that means the package truly isn't compatible with React 17, and you'll need to either downgrade React or switch to an alternative.

内容的提问来源于stack exchange,提问作者Ghulam Haider

火山引擎 最新活动