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

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

Open
kricsleo opened this issue Dec 16, 2024 · 0 comments · May be fixed by #458
Open

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

kricsleo opened this issue Dec 16, 2024 · 0 comments · May be fixed by #458
Labels
bug Something isn't working dts

Comments

@kricsleo
Copy link

kricsleo commented Dec 16, 2024

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

@kricsleo kricsleo added the bug Something isn't working label Dec 16, 2024
@kricsleo kricsleo linked a pull request Dec 17, 2024 that will close this issue
@pi0 pi0 mentioned this issue Dec 27, 2024
1 task
@pi0 pi0 added the dts label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants