navaid: Error: UMD and IIFE output formats are not supported for code-splitting builds.

I am following the example in the template provided after creating an app from the official svelte demo and I received the above ^ error when I set my rollup configuration file format to iife.

input: 'src/main.js', output: { sourcemap: true, format: 'iife', name: 'app', file: 'public/bundle.js' },

Or is this a rollup issue?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

This is odd, I do not get this error using a Svelte template on my Linux machine. My dev builds load fine. Then I switched to my Windows laptop and get this error - nothing has changed. I thought maybe I needed to updated some npm modules or something - and did that, and it doesn’t change anything. Same error.

Update: solved it by adding this to the rollup config:

inlineDynamicImports: true,

@mspanish, Alhamdulillah, thank you very much for the clue, finally the error disappeared. To make it clearer, in the code below I will write the rollup.config.js section again, hopefully it’s easier to understand.

export default { input: ‘src/main.js’, output: { sourcemap: true, format: ‘iife’, name: ‘app’, file: ‘public/build/bundle.js’, inlineDynamicImports: true },

It’s not a navaid nor a Rollup issue. The IIFE and UMD formats outright cannot be code-split.

You have to use the ESM, AMD, or SystemJS outputs, as configured in the template. I also spoke a tiny bit about this here.

In short, both IIFE and UMD formats are (purposefully) self-contained. By definition, you can’t export/“read” pieces of a UMD/IIFE file because its scope/contents are fully enclosed.

Hope that helps a bit~!