You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目使用html-to-text报错:selderee未导出Picker如何解决?

你遇到的这个导入报错是html-to-text9.x版本的依赖兼容性问题:该版本依赖的selderee包后续更新时调整了导出逻辑,移除了Picker对象的导出,导致依赖引用失败。

解决方法

方案1:降级到html-to-text 8.x稳定版(操作最简单,原有代码无需改动)

执行以下命令重装包即可:

  1. 卸载当前版本
    npm uninstall html-to-text
  2. 安装8.x版本
    npm install html-to-text@8

方案2:原生实现HTML转纯文本(无第三方依赖)

如果只是基础的HTML标签过滤需求,可以直接用浏览器DOM API实现,不需要引入任何第三方包:

function htmlToText(html) {
  const tempDiv = document.createElement('div')
  tempDiv.innerHTML = html
  return tempDiv.textContent || tempDiv.innerText || ''
}

// 调用示例
const html = `<p>My name is Shahid.</p>`
const text = htmlToText(html)

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 22:27:05