简体   繁体   English

Webpack,优化分块给出“冲突:多个块将资产发送到相同的文件名”错误

[英]Webpack, optimization chunking gives “Conflict: Multiple chunks emit assets to the same filename” error

Info信息

I am trying to generate my own webpack config and have some problems getting it working.我正在尝试生成自己的 webpack 配置并且在使其正常工作时遇到了一些问题。

Problem问题

When trying to use optimization to split files into chunks I get the a error like underneath当尝试使用优化将文件拆分为块时,我收到如下错误

Error: Conflict: Multiple chunks emit assets to the same filename static/js/bundle.js (chunks main and vendors-node_modules_react-hot-loader_patch_js-node_modules_react_jsx-dev-runtime_js-node_mod-4610d2)错误:冲突:多个块将资产发送到相同的文件名 static/js/bundle.js(块 main 和 vendor-node_modules_react-hot-loader_patch_js-node_modules_react_jsx-dev-runtime_js-node_mod-4610d2)

If I remove the optimization section it works but without chunking.如果我删除优化部分,它可以工作但没有分块。 I have looked to the create react app webpack.config.js to get something to reference while generating this.我查看了创建反应应用程序webpack.config.js以在生成此内容时获得一些参考。

As you can see they have the optimization section working with chunking in both development and production.正如您所看到的,他们的优化部分在开发和生产中都使用了分块。 Why do I get the conflict error when using it?为什么我在使用时会出现冲突错误?

Code代码

Minified/simplified version of my config (runtimeChunk disabled, as it also gives the same conflict error)我的配置的缩小/简化版本(runtimeChunk 已禁用,因为它也给出了相同的冲突错误)

webpack.config.js webpack.config.js

module.exports = () => {
    process.env.NODE_ENV = "development";
    process.env.BABEL_ENV = "development";

    return {
        mode: "development",
        entry: ["react-hot-loader/patch", "./src"],
        output: {
            path: undefined,
            publicPath: "/",
            filename: "static/js/bundle.js",
            chunkFilename: "static/js/[name].chunk.js",
        },
        optimization: {
            minimize: false,
            splitChunks: {
                chunks: "all",
                name: false
            },
            // runtimeChunk: {
            //     name: (entrypoint) => `runtime-${entrypoint.name}`,
            // },
        },
        resolve: {
            modules: [path.join(__dirname, "src"), "node_modules"],
            alias: {
                "react-dom": "@hot-loader/react-dom",
            },
        },
        module: {
            rules: [
                {
                    test: /\.(js|mjs|jsx|ts|tsx)$/,
                    include: path.resolve(__dirname, "./src"),
                    exclude: /node_modules/,
                    use: ["babel-loader"],
                },
            ],
        },
        plugins: [
            new HtmlWebpackPlugin({
                inject: true,
                template: path.resolve(__dirname, "./public/index.html"),
            }),
            new webpack.HotModuleReplacementPlugin(),
        ],
        devServer: {
            compress: true,
            hot: true,
            contentBase: "./build",
            historyApiFallback: true,
        },
        devtool: "inline-source-map",
    };
};

.babelrc .babelrc

{"presets": [["react-app", {"runtime": "automatic"}]]}

Got it to work had to change filename: "static/js/bundle.js" to filename: "static/js/[name].js"让它工作必须将filename: "static/js/bundle.js"更改为filename: "static/js/[name].js"

output: {
    path: undefined,
    publicPath: "/",
    filename: "static/js/[name].js",
    chunkFilename: "static/js/[name].chunk.js",
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复Webpack中的“冲突:多个资产发出相同的文件名”错误? - How to fix “Conflict: Multiple assets emit to the same filename” error in Webpack? 冲突中的错误:多个资产向相同的文件名发出不同的内容 - ERROR in Conflict: Multiple assets emit different content to the same filename 冲突:多个资产发出相同的文件名 - Conflict: Multiple assets emit to the same filename 冲突:多个块将资产发送到相同的文件名 ./plugin.min.css - Conflict: Multiple chunks emit assets to the same filename ./plugin.min.css Vue js npm 在 bundle.css 中运行构建错误 - Vue js npm run build error in bundle.css Conflict: Multiple chunks emit assets to the same filename bundle.css (chunks app and chunk-f33d301e) 使用带有 Quasar 的 MonacoEditor 组件时如何解决“冲突:多个资产将不同的内容发送到相同的文件名 fonts/codicon.ttf” - How to solve "Conflict: Multiple assets emit different content to the same filename fonts/codicon.ttf" when using MonacoEditor component with Quasar 多个资产向同一个文件名索引发出不同的内容。html - Multiple assets emit different content to the same filename index.html Webpack分块。 没有内容出现 - 没有加载块 - Webpack chunking. No content appearing - chunks not loaded webpack:带有webworker和多个块的commonchunksplugin - webpack: commonchunksplugin with webworker and multiple chunks 为什么 Webpack 在使用 webpackMode: "weak" 时不发出块? - Why doesn't Webpack emit chunks when using webpackMode: "weak"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM