解决 Multiple chunks emit assets to the same filename 错误

解决 Multiple chunks emit assets to the same filename 错误

问题描述:webpack打包多文件入口时,出现错误
ERROR in chunk module [entry]
./js/build.js
Conflict: Multiple chunks emit assets to the same filename ./js/build.js (chunks
 0 and 1)
 
问题原因:多文件入口,只指定了一个输出文件名
entry: {
        main: './src/js/main.js',
        module: './src/js/module.js'
},
output: {
    filename: './js/build.js',
    path: resolve(__dirname, 'build')
}

解决方案:每个需要打包的文件根据文件名打包输出
output: {
    filename: './js/[name].js',
    path: resolve(__dirname, 'build')
}

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
This issue typically occurs when multiple assets are emitted with different content but have the same filename. It can happen when using webpack's `output.filename` option or when using plugins like `MiniCssExtractPlugin` or `HtmlWebpackPlugin`. To resolve this issue, you can try the following solutions: 1. Ensure that each asset has a unique filename: Make sure that each asset emitted by webpack has a unique filename. You can use placeholders like `[name]`, `[id]`, or `[contenthash]` to generate unique filenames based on their content or other factors. 2. Use the `output.chunkFilename` option: If you are using code splitting or dynamic imports, you can configure the `output.chunkFilename` option to generate unique filenames for dynamically loaded chunks. For example: ```javascript output: { // ... chunkFilename: '[name].[contenthash].js', }, ``` 3. Check for conflicting plugins or loaders: If you are using plugins or loaders that manipulate the filenames, ensure that they are not conflicting with each other. Some plugins may override the filename configuration set by others, leading to conflicts. 4. Upgrade your webpack version: Sometimes, this issue can be caused by a bug in a specific version of webpack or its plugins. Upgrading to the latest version of webpack and its plugins may help resolve the problem. If none of these solutions work, please provide more details about your webpack configuration and any relevant plugins or loaders you are using, so I can assist you further.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值