Fix for ambiguous import resolution during AOT ngfactory file compilation #2667
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.
This fixes an issue with ambiguous import resolution that can come up when compiling
ngfactory
files with ambiguous import statements that are generated by the Angular ngc compiler for AOT.//cc @alexeagle
The issue was seen on the repo https://github.com/gregmagolan/abc-demo-build-with-aot-universal. To reproduce with the current closure-compiler HEAD, one additional patch to CompilerInput.java is needed to get the abc-demo-build-with-aot-universal build to work (as seen in this commit gregmagolan@5f21b3b). PR #2641, which has not been merged yet, resolves the need for this additional patch so its not included in the PR for that reason.
The compiler error seen is:
The import
'src/browser/app/app.component.closure'
is ambiguous so the current HEAD doesn't attempt to resolve usingresolveJsModuleNodeFileOrDirectory
. The fix is to tryresolveJsModuleNodeFileOrDirectory
first for all import types (absolute, relative and ambiguous) and thenresolveJsModuleFromRegistry
if the first doesn't resolve.To reproduce, you can point
package.json
inabc-demo-build-with-aot-universal
to a closure build from https://github.com/gregmagolan/closure-compiler/tree/angular-closure-fixes.Undo the patch in NodeModuleResolver.java from https://github.com/gregmagolan/closure-compiler/tree/angular-closure-fixes and you should see the above compile error.