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

broken d.ts in projects with default exports in separate files #193

Open
megastels opened this issue Sep 20, 2022 · 8 comments
Open

broken d.ts in projects with default exports in separate files #193

megastels opened this issue Sep 20, 2022 · 8 comments

Comments

@megastels
Copy link

megastels commented Sep 20, 2022

plugin generates broken declarations

  • Version: 2.0.5
  • Rollup Version: 2.79

Reproduction

Simple example

A.ts

export default "Module A";

B.ts

export default "Module B";

entry point

export { default as ModuleA } from './A';
export { default as ModuleB } from './B';

config

export default defineConfig({
    input: "src/index.ts",
    output: {
        file: "dist/index.js",
    },
    plugins: [
        ts(),
    ]
})

Expected Behavior

declare const _default_1: "Module A";
declare const _default_2: "Module B";
export { _default_1 as A, _default_2 as B };

Actual Behavior

// Cannot redeclare block-scoped variable '_default'.
declare const _default: "Module A";
declare const _default: "Module B";
export { _default as A, _default as B };
@tvooo
Copy link

tvooo commented Dec 12, 2022

I've been seeing the same issue for a while; thanks for providing the reproduction example, @megastels! I reckon this was caused by 16d24fa

I'd love to see this addressed :-) Happy to help too, but not sure how much time I'll have in the coming weeks.

@tvooo
Copy link

tvooo commented Dec 13, 2022

@wessberg I managed to add a test case with the above example; as expected, it fails. However, I'm unsure where to continue - all my console.logs are being swallowed when running the tests, for example 😄 . Any pointers?

@michaelfaith
Copy link

michaelfaith commented Mar 24, 2023

Came here to report this myself. Slightly different but similar scenario, and likely the same root cause. This is a pretty significant gap imho. Exporting default symbols is a very common use case.

In my case:
entry point:

export * from './colors';

export { default as ThemePalette } from './ThemePalette';
export * from './darkThemePalette';
export * from './lightThemePalette';

The bottom three work (even the default as ThemePalette, but the index.ts in the ./colors folder has a bunch more default exports, and those all end up broken.

/** colors/index.ts */
export { default as TonalPalette } from './TonalPalette';

export { default as common } from './common';
export { default as aqua } from './aqua';
export { default as blue } from './blue';
export { default as gray } from './gray';
export { default as grey } from './gray';
export { default as green } from './green';
export { default as orange } from './orange';
export { default as purple } from './purple';
export { default as red } from './red';
export { default as yellow } from './yellow';

Those all end up like this in the rolled up .d.ts:

export { default as TonalPalette, default as common, default as aqua, default as blue, default as gray, default as grey, default as green, default as orange, default as purple, default as red, default as yellow, ThemePalette, darkThemePalette, lightThemePalette };

@wycats
Copy link

wycats commented May 9, 2023

I've hit this too. Is there a workaround?

@runspired
Copy link

runspired commented Apr 28, 2024

also hit this, am being told the answer is to abandon this and rollup for vite and vite-plugin-ts 😭

@ronny1020
Copy link

Also, hit this, Is there a walkaround now?

@michaelfaith
Copy link

michaelfaith commented Jun 14, 2024

Also, hit this, Is there a walkaround now?

This may not be the most helpful answer, but i ultimately switched to the official TS plugin for rollup: @rollup/plugin-typescript (README). It did everything i needed, and was easy to swap in. This project looks to be abandoned.

@ronny1020
Copy link

I just switched torollup-plugin-dts for the definition files. I still use rollup-plugin-ts for the JS files, though.

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

No branches or pull requests

6 participants