[api-extractor] Report unresolvable inline import paths in .d.ts rollups - #5925
Merged
Sean Larkin (TheLarkInn) merged 1 commit intoAug 21, 2026
Conversation
Pham Manh Luc (MLuc24)
requested a review
from Ian Clanton-Thuon (iclanton)
as a code owner
August 17, 2026 06:56
When an inline import() type could not be resolved to a rolled up entity, its
span was emitted verbatim. A relative path such as import('../Bar') means
nothing next to the rollup, which does not preserve the original file layout,
so the emitted .d.ts does not compile and the only clue was an unrelated
ae-forgotten-export warning.
Such paths are now reported as ae-unresolved-import-path.
Pham Manh Luc (MLuc24)
force-pushed
the
fix/api-extractor-relative-import-path
branch
from
August 18, 2026 06:33
d804098 to
70346d1
Compare
Sean Larkin (TheLarkInn)
approved these changes
Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4507
Per Pete Gonzalez (@octogonz)'s conclusion on that issue — "Let's improve the error message: API Extractor could analyze the .d.ts output and identify import paths such as
../Barthat clearly don't make sense in a rollup, and report a more intuitive error message" — this adds a dedicatedae-unresolved-import-pathmessage for that case.Today an unresolvable inline
import()type is emitted into the rollup verbatim. The generated.d.tsthen contains a relative path that points nowhere, so it does not compile for consumers, and the only hint is anae-forgotten-exportwarning that names the symbol rather than the real problem.Details
In
DtsEmitHelpers.modifyImportTypeSpan, everything happens underif (referencedEntity). When the entity lookup fails there is noelse, so the span keeps its original text and the path survives into the rollup. The newelse ifinspects the import's module specifier and, when it is relative, reports the message against the same declaration.The check is deliberately narrow: only a specifier starting with
.is reported. A bare specifier that fails to resolve is a different situation (the rollup emits a realimportfor it), and the resolving case is untouched — see the negative test below.Two choices I would be happy to change: the message id name
ae-unresolved-import-path, and leaving it at the defaultwarningseverity rather than adding an entry toapi-extractor-defaults.json. Say the word and I will adjust either.I did not add a case under
build-tests/api-extractor-scenarios, because I could not regenerate the committed expected outputs locally (see below). Happy to add one if you would like it in this PR.How it was tested
Built the contrived example from the issue against
@microsoft/api-extractor7.58.12 —Bar.tsexporting an enum,foo/Foo.tsdeclaringexport type Foo = import('../Bar').Bar.A;, andindex.tsre-exportingFoo.Before, the rollup silently ends up unusable:
With this change applied, the cause is reported:
Negative test, to confirm it does not fire on inline imports that resolve normally — changing
Foo.tstoexport type Foo = import('../Bar').Bar;:Both runs were performed by applying this change to the published package's compiled output, since I could not run the monorepo's own
rush buildlocally. The API report incommon/reviews/api/api-extractor.api.mdwas updated by hand for the same reason, so it is worth confirming in CI that it matches.