Skip to content

declare module with local file path does not bundle correctly #134

@dragon-fish

Description

@dragon-fish

Describe the bug

See https://github.com/dragon-fish/rolldown-plugin-dts-playground

When bundling the typings for this project with rolldown-plugin-dts into a single file, all types are merged into dist/index.d.ts. However, the emitted declare module augmentations still reference their original source module paths (e.g. './foo.js', '@/foo.js') instead of the entry module. Because the augmentations now live in the entry declaration file, their targets should be rewritten to the entry module ('.'), otherwise downstream interface merging does not apply to the types exported from the package root.

// src/bar.ts
declare module './foo.js' {
  interface Foo {
    bar: string
  }
}
// src/sub/baz.ts
declare module '@/foo.js' {
  interface Foo {
    baz: number
  }
}

This makes the augmentations unreachable for consumers who import from the package root (the entry), so properties like bar and baz are missing on Foo at usage sites.

Expected Behavior

Since everything is flattened into dist/index.d.ts (the entry), the augmentation targets should be the entry module:

declare module '.' {
  interface Foo {
    bar: string
  }
}

declare module '.' {
  interface Foo {
    baz: number
  }
}

Either two separate blocks as above, or a single merged block, but the module specifier should be '.'.

Actual Behavior

Augmentations are emitted with their original source paths ('./foo.js', '@/foo.js') inside the flattened dist/index.d.ts, which no longer matches what consumers import from.

Reproduction

https://github.com/dragon-fish/rolldown-plugin-dts-playground

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600KF
    Memory: 5.60 GB / 31.84 GB
  Binaries:
    Node: 22.18.0 - D:\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Users\xiaoy\AppData\Roaming\npm\yarn.CMD
    npm: 10.9.3 - D:\nodejs\npm.CMD
    pnpm: 10.20.0 - C:\Users\xiaoy\AppData\Roaming\npm\pnpm.CMD
    bun: 1.3.1 - C:\Users\xiaoy\.bun\bin\bun.EXE
  Browsers:
    Chrome: 142.0.7444.60
    Edge: Chromium (140.0.3485.54)
    Firefox: 143.0.4 - C:\Program Files\Mozilla Firefox\firefox.exe

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributions

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions