webpack: Using splitChunks together with library causes undefined exports

I’m trying to create library, built by webpack. Creating an entry with some exported function works just fine. The problem starts when I add splitChunks property with any of these settings: chunks: "all", "async" or "initial". When I’m trying to use the exported module I got undefined.

Bug report

What is the current behavior? Using splitChunks and library makes exports undefined.

If the current behavior is a bug, please provide the steps to reproduce.

{
    entry: "bundle.ts",
    output: {
        library: "MyLibrary",
        libraryTarget: "window"
    },
    optimization: {
        splitChunks: {
            chunks: "all"
        }
    }
}

What is the expected behavior? Exported modules should be available in window.MyLibrary. I repeat, my current configuration, without splitChunks is fine and I can use my exported function.

Other relevant information: webpack version: 4.42.1, also checked on 5.23.0 Node.js version: 15.6.0 Operating System: Windows Additional tools: -

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 20 (6 by maintainers)

Most upvoted comments

Hi,

I’ve found an issue with my configuration and it came out I simply didn’t pull all the required chunks needed. Everything works as expected now.

Thanks for help!

You can get this information from stats, if you need good logic please look at HTMLWebpackPlugin code, it will be faster