Skip to content

[Bug]: Unable to bundle types from dependency while importing from root but works for sub-path modules #411

Open

Description

@Asuka109

Version

System:
    OS: macOS 15.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 151.06 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Safari: 18.0
  npmPackages:
    @rslib/core: ^0.0.16 => 0.0.16

Details

There is a minimal repro slimmed from a package using Rsbuild.

src/index.ts

import type { RsbuildPluginAPI as Foo } from 'my-kit';
import type { RsbuildPluginAPI as Bar } from 'my-kit/plugin';

export type { Foo, Bar };

While all the things is actually exported from ./node_modules/my-kit/dist-types/types/plugin.d.ts.

node_modules/my-kit/dist-types
├── index.d.ts
└── types
    ├── index.d.ts
    └── plugin.d.ts

The weird thing is if I import types from my-kit (./node_modules/my-kit/dist-types/index.d.ts). It will come into being a relative path import statement from ./types (but there no dist/types/index.d.ts or somethings like it in there).

dist/index.d.ts (actual)

import { RsbuildPluginAPI as Foo } from './types';

export declare type Bar = {};

export { Foo }

export { }

But I expected it should be bundle into the dist/index.d.ts just like if I import the some type from the sub-path module my-kit/plugin (./node_modules/my-kit/dist-types/types/plugin.d.ts). It would be seems like:

dist/index.d.ts (expected)

export declare type Foo = {};

export declare type Bar = {};

export { Foo, Foo }

Reproduce link

https://github.com/Asuka109/repro-rslib-relative-path-typings

Reproduce Steps

  1. pnpm install
  2. pnpm build

Activity

  1. self-assigned this
    on Nov 12, 2024
  2. Timeless0911 commented on Nov 25, 2024

    @Timeless0911
    Contributor

    same as #470

    If I write full index path like below, it work as expected.

    - export type { RsbuildPluginAPI } from './types';
    
    + export type { RsbuildPluginAPI } from './types/index';
    
  3. Asuka109 commented on Nov 25, 2024

    @Asuka109
    Author

    It sounds like a ES Module limitation or something which won't resolve any directory as a module by appending ./index...

  4. fi3ework commented on Nov 25, 2024

    @fi3ework
    Member

    type-fest is shipped in CJS mode, so api-extractor should follow Node.js resolution strategy, which should handles /index.

  5. Timeless0911 commented on Nov 26, 2024

    @Timeless0911
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-extractor@microsoft/api-extractor related issue🐞 bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions