microsoft / microsoft/TypeScript

Plugin probe path starts in incorrect location?

Đang mở
#62,618 2 bình luận 0 reaction 1 người được giao Xem trên GitHub

@sheetalkamat đang làm issue này rồi.

Từ ngày 17/10/2025.

Needs Investigation
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

The code to determine the global plugin search path is I think incorrect?

It joins the executing file path which includes the `typescript.js` or `tsserver.js` filename, with the `../../..` string which results in a path like: `X/node_modules/typescript/lib/tsserver.js/../../..` which means that the resultant path for this example is actually `X/node_modules` to which the resolve process appends a second `node_modules` folder resulting in looking for plugins in `X/node_modules/node_modules` so plugins never resolve.

```typescript
protected getGlobalPluginSearchPaths(): string[] {
// Search any globally-specified probe paths, then our peer node_modules
return [
...this.projectService.pluginProbeLocations,
// ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/
combinePaths(this.projectService.getExecutingFilePath(), "../../.."),
];
}
```
https://github.com/microsoft/TypeScript/blob/main/src/server/project.ts#L2110

The actual resolve then happens here and the `node_modules` folder is appended:

```typescript
public static importServicePluginSync(
pluginConfigEntry: PluginImport,
searchPaths: string[],
host: ServerHost,
log: (message: string) => void,
): PluginImportResult {
Debug.assertIsDefined(host.require);
let errorLogs: string[] | undefined;
let resolvedModule: T | undefined;
for (const initialDir of searchPaths) {
const resolvedPath = normalizeSlashes(host.resolvePath(combinePaths(initialDir, "node_modules")));
log(`Loading ${pluginConfigEntry.name} from ${initialDir} (resolved to ${resolvedPath})`);
const result = host.require(resolvedPath, pluginConfigEntry.name); // TODO: GH#18217
if (!result.error) {
resolvedModule = result.module as T;
break;
}
const err = result.error.stack || result.error.message || JSON.stringify(result.error);
(errorLogs ??= []).push(`Failed to load module '${pluginConfigEntry.name}' from ${resolvedPath}: ${err}`);
}
return { pluginConfigEntry, resolvedModule, errorLogs };
}
```
https://github.com/microsoft/TypeScript/blob/main/src/server/project.ts#L500

I believe this may be the root cause of a number of different issues raised here:
https://github.com/microsoft/TypeScript/issues/61584
https://github.com/microsoft/TypeScript/issues/44289

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.