rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.65k stars 590 forks source link

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

Open andreiduca opened 1 month ago

andreiduca commented 1 month ago

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:

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

carry0987 commented 1 month ago

Me too. The detail is here: #1772