Skip to content

[api-extractor] [feature request] Bundle imports using nodes subpath imports #myImport syntax #5238

Open
@DesselBane

Description

@DesselBane

Summary

Node 14.6.0/12.19.0 added support for subpath imports https://nodejs.org/api/packages.html#subpath-imports . In my project I use them to define aliases as these can be defined in one place and there is no need to specify them in your tsconfig and vite config.

{
  "name": "my-package",
  "imports": {
    "#myImport": "./src/my-module.ts"
  }
}

When bundling types using the vite-plugin-dts these imports stay the way ther are so

// source.ts
export type { MyType } from '#myImport'

// ===================================

// becomes index.d.ts
import { MyType } from '#myImport'
export { MyType }

This works if the source file (./src/my-module.ts) is included in the npm tarball as the subpath import is defined in the package.json. However I bundle the types in order to only include the dist folder so this becomes a problem.

Expected Result

The import should be resolved from #myImport into <packageRoot>/src/my-module.ts and then the regular bundling steps should be performed.

The dist output should not contain any sub-path imports defined in the package.json.

Details

I would expect this to be the default behavior rather than an extra config option (but maybe I'm missing something why this would not work)

This also does not work when specifying the import as bundledPackages in the config.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.52.8
Operating system? Windows
API Extractor scenario? rollups (.d.ts)
Would you consider contributing a PR? No/Maybe (not familiar with the codebase)
TypeScript compiler version? 5.8.3
Node.js version (node -v)? 22.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions