diff --git a/apps/api-extractor/src/api/CompilerState.ts b/apps/api-extractor/src/api/CompilerState.ts index 7c9513884c9..a14bcb1af40 100644 --- a/apps/api-extractor/src/api/CompilerState.ts +++ b/apps/api-extractor/src/api/CompilerState.ts @@ -67,6 +67,15 @@ export class CompilerState { ); } + // Delete outDir and declarationDir to prevent TypeScript from redirecting self-package + // imports to source files. When these options are set, TypeScript's module resolution + // tries to map output .d.ts files back to their source .ts files to avoid analyzing + // build outputs during compilation. However, API Extractor specifically wants to analyze + // the .d.ts build artifacts, not the source files. Since API Extractor doesn't emit any + // files, these options are unnecessary and interfere with correct module resolution. + delete commandLine.options.outDir; + delete commandLine.options.declarationDir; + const inputFilePaths: string[] = commandLine.fileNames.concat(extractorConfig.mainEntryPointFilePath); if (options && options.additionalEntryPoints) { inputFilePaths.push(...options.additionalEntryPoints); diff --git a/common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json b/common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json new file mode 100644 index 00000000000..6f8a769bf5a --- /dev/null +++ b/common/changes/@microsoft/api-extractor/fix-self-import-resolution_2025-08-07-10-22.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/api-extractor", + "comment": "Fix self-package import resolution by removing outDir/declarationDir from compiler options", + "type": "patch" + } + ], + "packageName": "@microsoft/api-extractor" +} \ No newline at end of file