Skip to content

Commit ffa4992

Browse files
finalchildclaude
andauthored
[api-extractor] Fix self-package import resolution in TypeScript compiler (#5301)
When analyzing .d.ts files that import the package itself, TypeScript's module resolution would redirect to source .ts files instead of analyzing the build artifacts. This occurs because TypeScript tries to avoid analyzing build outputs when outDir/declarationDir are set. Fix by deleting outDir and declarationDir options from the compiler configuration, as API Extractor only uses the compiler for analysis and doesn't emit files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: finalchild <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent d420c67 commit ffa4992

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

apps/api-extractor/src/api/CompilerState.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ export class CompilerState {
6767
);
6868
}
6969

70+
// Delete outDir and declarationDir to prevent TypeScript from redirecting self-package
71+
// imports to source files. When these options are set, TypeScript's module resolution
72+
// tries to map output .d.ts files back to their source .ts files to avoid analyzing
73+
// build outputs during compilation. However, API Extractor specifically wants to analyze
74+
// the .d.ts build artifacts, not the source files. Since API Extractor doesn't emit any
75+
// files, these options are unnecessary and interfere with correct module resolution.
76+
delete commandLine.options.outDir;
77+
delete commandLine.options.declarationDir;
78+
7079
const inputFilePaths: string[] = commandLine.fileNames.concat(extractorConfig.mainEntryPointFilePath);
7180
if (options && options.additionalEntryPoints) {
7281
inputFilePaths.push(...options.additionalEntryPoints);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fix self-package import resolution by removing outDir/declarationDir from compiler options",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor"
10+
}

0 commit comments

Comments
 (0)