egoist / egoist/tsup

Failed to generate dts with custom loader & manual type declaration

Open
#954 0 comments 7 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

I'm trying to import svg files using text loader.

`tsup.config.ts`
```typescript
import { defineConfig } from 'tsup';
import { dependencies } from './package.json';

export default defineConfig({
entry: ['src/**/!(*.stories|*.test|*.d).(tsx|ts|jsx|js)'],
format: ['esm'],
target: 'esnext',
external: [
...Object.keys(dependencies),
],
loader: {
'.svg': 'text',
},
dts: true,
});

```

`src/assets/icons.ts`
```typescript
export { default as ascending } from './icons/ascending.svg';
export { default as barGraph } from './icons/barGraph.svg';
export { default as bookmarkOff } from './icons/bookmark-off.svg';
```

and then create a manual declaration file at the project root

`src/types.d.ts`
```typescript
declare module '*.svg' {
const src: string;
export default src;
}
```
It built well, but failed to generate d.ts with this error
```
RollupError: "default" is not exported by "src/assets/icons/ascending.svg", imported by "src/assets/icons.ts".
```

Contributor guide

Open the contributing guide

Research direction

Start with tsup.config.ts and the dts: true path, then inspect how src/assets/icons.ts imports the SVG files and how src/types.d.ts is considered. Reproduce the build with the custom .svg text loader; done means declaration generation completes without the RollupError for the SVG default export.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.