developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8k stars 361 forks source link

Error: Invalid value "umd" for option "output.format" #1032

Closed DVitaliy closed 11 months ago

DVitaliy commented 1 year ago

I'm getting error:

Error: Invalid value "umd" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.

if inside method of class has import

class Test {
  json = "";
  async load() {
    const json = await import("./json.json");
    this.json = json.default.find((item) => item.name === "name 2")?.name ?? "";
  }
}

The source code here https://codesandbox.io/s/focused-sun-igsymq

PS: If change output format (for ex. esm or cjs) then OK

rschristian commented 1 year ago

I think I'd label this as "Working as intended". Dynamic imports make little sense inside of UMD and would need to be translated into another form, hence why Rollup does not support doing this out-of-the-box.

There are some Babel plugins that will transform this, just depends on what your targets are. I don't think this is something we should handle, personally.