egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.29k stars 223 forks source link

Error when trying to resolve augmented modules via `--dts-only` and `--dts-resolve` #1239

Open SplinterStan opened 1 month ago

SplinterStan commented 1 month ago

Problem

Version info

Repro

  1. Create a new package called tsup-augmented-module via npm init and put inside index.d.ts module augmentation, e.g.:

    
    declare module "tsup-augmented-module" {
    
    export type SetupOptions = {
        token: string;
        someOtherOption?: number;
    };

}

2. Specify `"types": "index.d.ts"` in `package.json`.
3. Create another consumer module via `npm init` and put your augmented module as dependency:

"dependencies": { "tsup-augmented-module": "file:../tsup-augmented-module", }

4. Now, in your `index.ts` write: 

import { SetupOptions } from 'tsup-augmented-module';

export function test(options: SetupOptions): string { return 'test accomplished!'; }

5. Now, run `npx tsup --entry index.ts --dts-only --dts-resolve ` and see an error like: 

RollupError: "SetupOptions" is not exported by 'tsup-augmented-module', imported by "./index.ts".



## Expectation
As typescript complier is able to resolve augmented modules, `tsup` should be able to as well.

<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund

- We're using [Polar.sh](https://polar.sh/egoist) so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.

<a href="https://polar.sh/egoist/tsup/issues/1239">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/egoist/tsup/issues/1239/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/egoist/tsup/issues/1239/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->
unional commented 1 month ago

I'm probably facing the same issue. There is the repro: https://github.com/repobuddy/storybook-image-snapshot

branch: rollup-dts

npm i
npm build
> tsup

CLI Building entry: src/index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v8.3.0
CLI Using tsup config: /home/unional/code/repobuddy/sis/tsup.config.ts
CLI Target: chrome100,safari15,firefox91,node18
CLI Cleaning output folder
ESM Build start
Generated an empty chunk: "index".
ESM dist/index.js     68.00 B
ESM dist/index.js.map 69.00 B
ESM ⚡️ Build success in 19ms
DTS Build start
node_modules/rollup/dist/rollup.d.ts (9:0): "Decorator" is not exported by "node_modules/@types/estree/index.d.ts", imported by "node_modules/rollup/dist/rollup.d.ts".
Error: error occured in dts build
    at Worker.<anonymous> (/home/unional/code/repobuddy/sis/node_modules/tsup/dist/index.js:1543:26)
    at Worker.emit (node:events:514:28)
    at MessagePort.<anonymous> (node:internal/worker:263:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:814:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
unional commented 1 month ago

Maybe related to #1231