microsoft / microsoft/TypeScript

subpath imports should play well with project references

オープン
#62,880 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

@andrewbranch がすでに取り組んでいます。

2025年12月12日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### 🔎 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。