Skip to content

Bundled .d.ts drops type modifier on type-only imports/exports #230

@silverwind

Description

@silverwind

The dts bundler emits plain import { ... } and export { ... } for symbols that the source declared as type-only, instead of import type { ... } / export { type ... }.

Reproduced on rolldown-plugin-dts@0.24.0-beta.1 with rolldown@1.0.0-rc.17.

Under rolldown 1.0.0-rc.17, this becomes a hard build failure when the imported names are not value exports of the importee — rolldown rc.17 promoted MISSING_EXPORT between TS modules from a warning to an error in rolldown#9197 (commit cc38b86). Builds that previously emitted this as silenced warnings now abort with errors like:

[MISSING_EXPORT] Error: "Foo" is not exported by "node_modules/some-pkg/index.d.ts".

Minimal reproduction

package.json:

{"type":"module","devDependencies":{"rolldown":"1.0.0-rc.17","rolldown-plugin-dts":"0.24.0-beta.1","typescript":"6.0.3"}}

rolldown.config.ts:

import {defineConfig} from "rolldown";
import {dts} from "rolldown-plugin-dts";

export default defineConfig({
  input: "src/index.ts",
  external: ["pkg"],
  plugins: [dts()],
});

src/index.ts:

declare module "pkg" {
  export const value: number;
  export type T = string;
}

import {value} from "pkg";
import type {T} from "pkg";

export const x = value;
export type Y = T;

Run:

pnpm install
pnpm exec rolldown -c

Actual output (dist/index.d.ts)

import { T } from "pkg";        // T is type-only — no `type` modifier

declare module "pkg" {
  const value: number;
  type T = string;
}
declare const x: any;
type Y = T;

export { Y, x };                // Y is a type — no `type` modifier

Expected output

import type { T } from "pkg";

declare module "pkg" {
  const value: number;
  type T = string;
}
declare const x: any;
type Y = T;

export { type Y, x };

Real-world impact

In a real project with verbatimModuleSyntax: true and an external module that uses export = X (e.g. dayjsDayjs, ConfigType, OpUnitType, OptionType only exist via the namespace), the missing type modifier turns those names into invalid value imports. With rolldown rc.17 the build fails with multiple MISSING_EXPORT errors aggregated from the dts bundling step.

Versions

rolldown-plugin-dts: 0.24.0-beta.1 (also reproduces on 0.23.2)
rolldown: 1.0.0-rc.17
typescript: 6.0.3

Related


This issue was written with the help of Claude Opus 4.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions