plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[rollup-plugin-typescript] Using a nested path for the declarationDir option always throws an error

Open andreiduca opened this issue 1 year ago • 1 comments

  • Rollup Plugin Name: rollup-plugin-typescript
  • Rollup Plugin Version: 12.1.1
  • Rollup Version: 4.24.0
  • Operating System (or Browser): macOs 14.7
  • Node Version: 20.11.1
  • Link to reproduction: https://stackblitz.com/edit/rollup-ts-5fhnsy?file=rollup.config.js

Expected Behavior

When using the declarationDir option with a nested path, npm build should output the bundled code in the dist folder, and the type declarations in the dist/types folder.

// rollup.config.js
import typescript from '@rollup/plugin-typescript';

export default {
  input: 'src/main.ts',
  output: [
    { file: 'dist/main.esm.js', format: 'esm' },
    { file: 'dist/main.umd.js', format: 'umd' },
  ],
  plugins: [
    typescript({
      tsconfig: './tsconfig.json',
      compilerOptions: {
        target: 'es6',
        baseUrl: './',
        outDir: './dist',
        declaration: true,
        declarationDir: './dist/types',
      },
    }),
  ],
};

This was working in 12.1.0, as seen here: https://stackblitz.com/edit/rollup-ts-afeykb?file=rollup.config.js

Actual Behavior

In 12.1.1, the command fails with the following error:

[!] (plugin typescript) RollupError: [plugin typescript] @rollup/plugin-typescript: Path of Typescript compiler option 'declarationDir' must be located inside the same directory as the Rollup 'file' option.

Additional Information

I tried different combinations of relative paths for both outDir and declarationDir, but none worked:

  • outDir: 'dist' and declarationDir: 'dist/types'
  • outDir: './dist' and declarationDir: 'dist/types'
  • outDir: 'dist' and declarationDir: './dist/types'
  • outDir: './dist' and declarationDir: './dist/types'
  • outDir: 'dist' and declarationDir: 'types'
  • outDir: './dist' and declarationDir: 'types'
  • outDir: 'dist' and declarationDir: './types'
  • outDir: './dist' and declarationDir: './types'

The only combination that works is using dist for both, but that defeats the purpose of having the types in a nested folder:

  • outDir: 'dist' and declarationDir: 'dist'

andreiduca avatar Oct 16 '24 21:10 andreiduca