egoist / egoist/tsup

Error: namespace must have a "ModuleBlock" body.

Open
#1,343 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

the dts will fail when namespaces are nested and declared is a different body.

```ts
export namespace cmath {}
export namespace cmath.delta {}
export namespace cmath.vector2 {}
...
```

This works perfectly fine and a valud ts, and works well with other compilers, this fails with dts with
```
Error: namespace must have a "ModuleBlock" body.

361 | function powerset(arr: T[], k?: number): T[][];
362 | }
> 363 | declare namespace cmath.delta {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

at DeclarationScope.convertNamespace (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:5749:17)
at Transformer.convertNamespaceDeclaration (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:5917:15)
at Transformer.convertStatement (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:5891:23)
at new Transformer (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:5836:16)
at convert (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:5827:27)
at Object.transform (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:6227:29)
at Object.writeFile (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/rollup.js:6366:55)
at writeFile (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/typescript.js:20370:8)
at printSourceFileOrBundle (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/typescript.js:120018:5)
at emitDeclarationFileOrBundle (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/typescript.js:119911:26)
Error: error occurred in dts build
at Worker. (/Users/softmarshmallow/Documents/Apps/grida/grida/node_modules/.pnpm/tsup@8.5.0_jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/dist/index.js:1545:26)
at Worker.emit (node:events:518:28)
at MessagePort. (node:internal/worker:268:53)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
at MessagePort. (node:internal/per_context/messageport:23:28)
DTS Build error
 ELIFECYCLE  Command failed with exit code 1.
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the nested namespace declarations shown in the issue and trace the dts build through DeclarationScope.convertNamespace and Transformer.convertNamespaceDeclaration in tsup's declaration bundling path. Done means the dts build accepts these valid nested namespaces and emits declarations without the ModuleBlock error.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.