React项目使用html-to-text报错:selderee未导出Picker如何解决?
你遇到的这个导入报错是html-to-text9.x版本的依赖兼容性问题:该版本依赖的selderee包后续更新时调整了导出逻辑,移除了Picker对象的导出,导致依赖引用失败。
解决方法
方案1:降级到html-to-text 8.x稳定版(操作最简单,原有代码无需改动)
执行以下命令重装包即可:
- 卸载当前版本
npm uninstall html-to-text - 安装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
相关产品推荐
相关产品推荐

