Skip to content

The default export declaring in .d.cts is not accurate. #457

@kricsleo

Description

@kricsleo

Environment

Node.js: *
unbuild: v3.0.1

Reproduction

https://stackblitz.com/edit/vitejs-vite-t55rnaxz?file=package.json,tsconfig.json,build.config.ts,src%2Findex.ts,dist%2Findex.d.cts&terminal=dev

Describe the bug

First run build, this will emit the cjs output.

The source index.ts only contains a default export:

export default function add(): number {
  return 42
}

In the index.cjs output, there is only the default export (this is correct ✅):

module.exports = add;

But the index.d.cts output, it's:

export { add as default };

this is wrong ❌, because this would lead to ❗️ Incorrect default export . You can run check to verify this problem.

And it should be:

export = add;

Another build tool tsup could have encountered the same problem, but they introduced a fix for this:
https://github.com/egoist/tsup/blob/cd03e1e00ec2bd6676ae1837cbc7e618ab6a2362/src/rollup.ts#L92-L109

They manually replaced this from export { XXX as default }; to export = XXX;

I'm wondering if we could do the same for unbuild ❤️.

(If that's the solution, I can popup a PR for it 🙌🏻)

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions