microsoft / microsoft/TypeScript

subpath imports should play well with project references

未关闭
#62,880 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@andrewbranch 已经在做这个了。

开始于 2025年12月12日。

Needs Investigation
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。