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

在Electron应用中安装@heroicons/react时出现DLL错误如何解决?

解决@heroicons/react Webpack DLL 编译找不到包的方案

原因说明

这个问题是因为@heroicons/react v2及以上版本采用纯ES模块规范导出,默认的Webpack DLL配置如果没有做ES模块兼容、或者入口配置漏加该依赖,就会触发找不到模块的报错。

修复步骤

  • 第一步:确认dll配置入口已添加该依赖
    打开你的webpack.dll.config.js,在entry的vendor数组里明确加入@heroicons/react,参考配置:
module.exports = {
  entry: {
    // 其他依赖保留,新增@heroicons/react
    vendor: ['react', 'react-dom', '@heroicons/react']
  },
  // 其他原有配置
}
  • 第二步:添加ES模块转译规则
    在dll配置的module.rules中新增针对@heroicons包的转译规则,确保webpack可以正确识别它的ES模块导出:
module.exports = {
  // 其他原有配置
  module: {
    rules: [
      // 其他原有规则保留,新增以下规则
      {
        test: /\.jsx?$/,
        include: /node_modules\/@heroicons/,
        use: ['babel-loader']
      }
    ]
  }
}

如果你的项目用TypeScript,还要确认tsconfig.json中的moduleResolution配置为node16或bundler,避免模块解析失败。

  • 第三步:重新生成dll文件
    先删除已生成的旧dll文件(通常存放在public/dll或你自定义的dll输出目录),再运行dll编译命令,比如npm run build:dll,确认编译过程无报错。
  • 第四步:校验DllReferencePlugin配置
    确认项目主webpack配置中的DllReferencePlugin指向的manifest.json路径和你dll编译输出的manifest路径完全一致,参考配置:
const DllReferencePlugin = require('webpack/lib/DllReferencePlugin')
module.exports = {
  plugins: [
    new DllReferencePlugin({
      manifest: require('./dist/vendor-manifest.json') // 替换为你实际的manifest文件路径
    })
  ]
}

替代方案

如果上述步骤配置后还是有问题,可以直接把@heroicons/react从dll入口数组中移除,让业务代码的编译流程处理该依赖。该包体积很小,不进dll对打包速度的影响几乎可以忽略,也能直接解决问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 15:36:05