Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andreiduca opened this issue Oct 16, 2024 · 1 comment · May be fixed by #1800

Comments

@andreiduca
Copy link

andreiduca commented Oct 16, 2024

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'
@carry0987
Copy link

Me too. The detail is here: #1772

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants