title: rollup esm and umd builds, with typescript plugin and declarations, not possible?
body: <p>I want to use rollup to make two builds of my library, an UMD version as well as a never ESM version</p>
  <p>Earlier my configuration when using the non official plugin <a href="https://github.com/ezolenko/rollup-plugin-typescript2" rel="nofollow noreferrer">rollup-plugin-typescript2</a> looked like this:</p>
  <pre><code>import typescript from 'rollup-plugin-typescript2'
  import pkg from '../package.json'
  export default {
    input: 'src/index.ts',
    output: [
      {
        file: pkg.main,
        format: 'umd',
        name: pkg.name,
        sourcemap: true
      },
      {
        file: pkg.module,
        format: 'esm',
        sourcemap: true
      },
    ],
  plugins: [
      typescript({
          tsconfig: &quot;src/tsconfig.json&quot;,
          useTsconfigDeclarationDir: true
      }),
    ],
  }
  </code></pre>
  <p>And in my package json I have:</p>
  <pre><code>  (...)
    &quot;scripts&quot;: {
      &quot;build&quot;: &quot;rollup -c ./scripts/dist.js&quot;,
    },
    &quot;main&quot;: &quot;dist/index.js&quot;,
    &quot;module&quot;: &quot;dist/index.esm.js&quot;,
    &quot;files&quot;: [
      &quot;dist&quot;
    ],
    (...)
  </code></pre>
  <p>And in my tsconfig.json I have:</p>
  <pre><code>  (...)
    &quot;compilerOptions&quot;: {
      &quot;rootDir&quot;: &quot;./src&quot;,
      &quot;outDir&quot;: &quot;./dist&quot;,
      &quot;declaration&quot;: true,
      &quot;declarationDir&quot;: &quot;./dist/@types/chrisweb-utilities&quot;,
      (...)
  </code></pre>
  <p>The resulat was &quot;created dist/index.js, dist/index.esm.js in 2.6s&quot; ... all good</p>
  <p>The files that got created where the following:</p>
  <pre><code>/dist
  |-@types
   |-index.d.ts
  |-index.js
  |-index.esm.js
  |-index.esm.js.map
  |-index.js.map
  </code></pre>
  <p>Today I tried to use the official plugin <a href="https://github.com/rollup/plugins/tree/master/packages/typescript/#readme" rel="nofollow noreferrer">@rollup/plugin-typescript</a> instead (because I use that one in other projects where I only do a single ESM build and it works without a problem and I wanted to use the same plugins through out all of my projects)</p>
  <p>I had a first error because of the  configuration propery only rollup-plugin-typescript2 understands:
  &quot;(!) Plugin typescript: @rollup/plugin-typescript TS5023: Unknown compiler option 'useTsconfigDeclarationDir'.&quot;</p>
  <p>So I removed it, which fixed that problem ...</p>
  <p>But I got another error: &quot;[!] (plugin typescript) Error: @rollup/plugin-typescript: 'dir' must be used when 'outDir' is specified.&quot;</p>
  <p>So I added dir to my configuration, which then looked like this:</p>
  <pre><code>import typescript from '@rollup/plugin-typescript';
  import pkg from '../package.json'
  export default {
    input: 'src/index.ts',
    output: [
      {
        file: pkg.main,
        format: 'umd',
        name: pkg.name,
        sourcemap: true,
        dir: &quot;dist&quot;,
      },
      {
        file: pkg.module,
        format: 'esm',
        sourcemap: true,
        dir: &quot;dist&quot;,
      },
    ],
  plugins: [
      typescript({
          tsconfig: &quot;tsconfig.json&quot;,
      }),
    ],
  }
  </code></pre>
  <p>Nope, next error shows up: &quot;[!] Error: You must set either &quot;output.file&quot; for a single-file build or &quot;output.dir&quot; when generating multiple chunks.&quot;</p>
  <p>Actually I don't even want to generate chunks, I'm fine with a single file, but I remove dir I'm back to the previous error. So next thing I tried was to keep &quot;dir&quot; and instead remove &quot;file&quot;</p>
  <p>This worked, or at least I got a success message: &quot;created dist, dist in 2.6s&quot; but the problem now is that instead of having two builds I just have a single one &quot;dist/index.js&quot;, the first build for UMD gets owerwritten by the second one for ESM.</p>
  <p>I thought ok one last try, lets output the UMD version in a subfolder of /dist and the ESM version in another one, so I changed my config to this:</p>
  <pre><code>  (...)
    output: [
      {
        format: 'umd',
        name: pkg.name,
        sourcemap: true,
        dir: &quot;dist/umd&quot;,
      },
      {
        format: 'esm',
        sourcemap: true,
        dir: &quot;dist/esm&quot;,
      },
    ],
    (...)
  </code></pre>
  <p>This failed too :( this time with this error: &quot;[!] (plugin typescript) Error: @rollup/plugin-typescript: 'outDir' must be located inside 'dir'.&quot; So my outDir is &quot;./dist&quot; which yes is not in dir: &quot;dist/umd&quot; anymore, I only have one outDir in tsconfig, so it can't be in each rollup output.dir, or do I miss something here?</p>
  <p>Oh and I actually also tried something else, remember that earlier error where rollup told me that &quot;'dir' must be used when 'outDir' is specified&quot;, so I removed outDir from tsconfig.json and hey another rollup error (at this point I think I got all possible rollup errors ;) ) which was the following: &quot;[!] (plugin typescript) Error: @rollup/plugin-typescript: 'dir' must be used when 'declarationDir' is specified.&quot;</p>
  <p>So I also commented out &quot;declarationDir&quot; in the tsconfig ... no more error, but this is not really the solution as now I don't have typescript type definition files getting generated.</p>
  <p>I went back and forth and tried all combinations for hours, but no luck so far...</p>
  <p>So I'm stuck and was wondering if someone can help me out? Maybe you had this or a similar problem? Either I'm missing something or this a bug in which case I will open a ticket in a few days.</p>