microsoft / microsoft/TypeScript

subpath imports should play well with project references

Ouverte
#62,880 1 commentaire 0 réactions 1 personne assignée Voir sur GitHub

@andrewbranch y travaille déjà.

Depuis le 12/12/2025.

Needs Investigation
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

### 🔎 Search Terms

tsconfig, resolve, package, imports, module, references

### 🕗 Version & Regression Information

5.9.3

TS project refererences in combination with subpath imports mapping to installed packages break Node.js projects.

### ⏯ Playground Link

_No response_

### 💻 Code

```ts
// @scope/alice/src/index.ts
import "@scope/bob/module"; // ok
import "#bob/module"; // breaks
```

```jsonc
// @scope/alice/tsconfig.json
{
"files": [],
"include": [],
"references": { "path": "./tsconfig.other.json" }
}
```

```jsonc
// @scope/alice/tsconfig.other.json
// appears in the error message, but its content should be irrelevant, given
// that @scope/bob/module imports work.
{
"compilerOptions":
{
"composite": true,
// ...
},
"files": [
// whatever, except for files from node_modules, therefore excluding @scope/bob
],
}
```

```json
{
"// package.json": "",
"name": "@scope/alice",
"type": "module",
"imports": {
"#bob/*": "@scope/bob/*"
},
"dependencies": {
"@scope/bob": "*"
},
"// ...": ""
}
```

```sh
tsc --build --noEmit
```

### 🙁 Actual behavior

An error of this kind:

```txt
src/index.ts:3:8 - error TS6307: File '/absolute/path/to/mono-repo/packages/bob/src/module/index.ts' is not listed within the file list of project '/absolute/path/to/mono-repo/packages/alice/tsconfig.other.json'. Projects must list all files or use an 'include' pattern.
File is ECMAScript module because '/absolute/path/to/mono-repo/packages/bob/package.json' has field "type" with value "module"

import "#bob/module"; // breaks
~~~~~~~~~~~~~
```

### 🙂 Expected behavior

Should build just fine, since subpath imports are nothing but a string rewriting mechanism (think: URL shortener). TSC should recognize that `#bob/*` refers to the modules in the external package `@scope/bob/*` from within `node_modules`, rather than treating it as project internal.

### Additional information about the issue

This can't be reproduced on the playground. I am willing to setup a repro repo, if the code in this issue is not sufficient to figure out what's going on.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.