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

已导入he模块但报错TypeError: he.decode is not a function的问题

解决he.decode is not a function错误的方案
  • 先补装核心模块:
    你之前只安装了类型定义包@types/he,但它只是给TypeScript提供类型提示的,实际的HTML实体解码功能来自he核心包。执行命令安装核心模块:

    npm install he
    
  • 调整导入方式:
    把命名空间导入改成默认导入,适配he模块的导出结构:

    import he from 'he';
    

    之后再调用he.decode(animal_stuff)就能正常输出解码后的干净字符串。

  • 简单测试验证:
    可以用这段代码快速确认修复效果:

    import he from 'he';
    const animal_stuff = '<cat>&dog';
    console.log(he.decode(animal_stuff)); // 输出: <cat>&dog
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 08:17:03