9

With only one output entry in my rollup.config.js like so:

export default {
  input: './src/Index.tsx',
  output: {
    dir: './myBundle/bundle',
    format: 'iife',
    sourcemap: true,
  },
  plugins: [
    typescript(),
    nodeResolve(),
    commonjs(),
    babel(),
    json(),
    terser(),
  ],
};

Why does Rollup accuse me of code-splitting? [!] Error: UMD and IIFE output formats are not supported for code-splitting builds.

Langostino
  • 121
  • 2
  • 5
  • 1
    Apparently from glancing at some github threads that came up when I googled your error message, you can't use dynamic imports with rollup if you're doing IIFE or UMD. If you're not using dynamic imports in your Typescript code, then IDK. – Jared Smith Jan 12 '21 at 19:49
  • 1
    I am using dynamic imports in my Typescript code. Does this mean my only option is to use ES module format in my output? – Langostino Jan 12 '21 at 19:55
  • 1
    No you can use commonjs (and probably AMD although I didn't check). You just can't use IIFE or UMD. But the dynamic import is why it's complaining about code splitting. Given how many github issues pop up on different repositories when you google that message, I'd say they may want a clearer one. – Jared Smith Jan 12 '21 at 19:57
  • My issue with CommonJS is that it outputs `require` into my bundle, which is not defined in the browser. – Langostino Jan 13 '21 at 01:00

2 Answers2

19

Encountered this problem using Routify. Adding inlineDynamicImports: true in rollup.config.js solved the problem for me

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

svelte - import dependency package with error

jsonderulo
  • 1,241
  • 1
  • 12
  • 18
1

You should set format equal to esm or es

GHOST
  • 94
  • 3
  • 1
    setting inlineDynamicImports to true resolved the issue for me even when format is set to 'system' as creates umd and es outputs. sorry I got only one vote on this – Lazaros Kosmidis Sep 24 '21 at 08:47