Skip to content

Module resolution fails when substituion path exists but original path directory does not #41281

@Gozala

Description

@Gozala

TypeScript Version: 3.7.x-dev.201xxxxx

It appears that

Path substitution fails to resolve module if original path (path before substitution) directory does not exists. E.g. if module is importing module bar and corresponding package.json has "main": "src/index.js" but directory src does not exists, but substitution path like dist/src/index.d.ts exists module resolution fails.

Here is the repo with minimial reproducible example illustrating this problem https://github.com/Gozala/bug-tsc-path-substitution/tree/main-field-bug

P.S.: Appears to fail with typescript@next as well.

Search Terms:

  • typeVersions
  • path mapping

Code

package.json

{
  "name": "bar",
  "main": "src/index.js",
  "typesVersions": {
    "*": {
      "*": [
        "dist/*"
      ]
    }
  }
}

dist/src/index.d.ts

declare class Bar {
}

export default Bar

Expected behavior:

Module resolution should succeed

Actual behavior:

Module resolution fails

Playground Link:

This involves multiple files, please see example repo instead
https://github.com/Gozala/bug-tsc-path-substitution/tree/main-field-bug

Related Issues:

Metadata

Metadata

Assignees

Labels

RescheduledThis issue was previously scheduled to an earlier milestoneWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions