Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ambiguous import resolution during AOT ngfactory file compilation #2667

Closed
wants to merge 1 commit into from

Conversation

gregmagolan
Copy link
Contributor

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:

./closure-bin/src/browser/app/app.component.ngfactory.closure.js:4: ERROR - Failed to load module "src/browser/app/app.component.closure"
import * as i3 from 'src/browser/app/app.component.closure';
^

The import 'src/browser/app/app.component.closure' is ambiguous so the current HEAD doesn't attempt to resolve using resolveJsModuleNodeFileOrDirectory. The fix is to try resolveJsModuleNodeFileOrDirectory first for all import types (absolute, relative and ambiguous) and then resolveJsModuleFromRegistry if the first doesn't resolve.

To reproduce, you can point package.json in abc-demo-build-with-aot-universal to a closure build from https://github.com/gregmagolan/closure-compiler/tree/angular-closure-fixes.

    "build:browser:closure": "yarn build:closure-bin && java -jar <patch to compiler>/compiler.jar --flagfile closure.browser.conf",

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.

@ChadKillingsworth
Copy link
Collaborator

ChadKillingsworth commented Oct 5, 2017

We cannot accept this change. It breaks the node module resolution. If an import path does not begin with a ., ../ or /, it should be looked up via the node module resolution algorithm.

Your generated source files should be changed to be compatible with the node module resolution algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants