Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Gozala opened this issue Oct 27, 2020 · 1 comment
Assignees
Labels
Rescheduled This issue was previously scheduled to an earlier milestone Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Gozala
Copy link

Gozala commented Oct 27, 2020

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:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 4, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.1 milestone Nov 4, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2021
@rbuckton
Copy link
Member

This doesn't appear to be a bug, but is the intended behavior of the feature. typesVersions is only used to override types specific to a version of TypeScript given a module that we could have resolved without typesVersions. Even though you have specified a TS version of *, typesVersions still requires a valid original path to override. As such, y\You must have a file at the main path for us to start with, even if that file is an empty index.d.ts or index.js file.

@rbuckton rbuckton added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 30, 2023
@RyanCavanaugh RyanCavanaugh removed the Bug A bug in TypeScript label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rescheduled This issue was previously scheduled to an earlier milestone Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants