Skip to content

Bazel build of router broken in 6.0.5 #24521

Closed

Description

@alexeagle

This commit
d20877b#diff-c68ccdefc54b5e3375135dddaa34d46c
causes ngc to produce a summary file

{"__symbol":110,"name":"ɵEmptyOutletComponent","filePath":"./router"},
{"__symbol":111,"name":"ApplicationRef","filePath":"@angular/core"},
{"__symbol":112,"name":"SystemJsNgModuleLoader","filePath":"@angular/core"},
{"__symbol":113,"name":"ɵflatten","filePath":"./router"},
{"__symbol":114,"name":"ɵEmptyOutletComponentNgFactory","filePath":"./router.ngfactory"},
{"__symbol":115,"name":"View_ɵEmptyOutletComponent_0","filePath":"./router.ngfactory"},
{"__symbol":116,"name":"RenderType_ɵEmptyOutletComponent","filePath":"./router.ngfactory"}]}

to point to a ngfactory in a way that breaks the compile:
angular/angular-bazel-example#154

ERROR: /home/circleci/ng/src/hello-world/BUILD.bazel:13:1: Compiling Angular templates (ngc) //src/hello-world:hello-world failed (Exit 1)

: Error: Could not resolve ./router.ngfactory from /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular_bazel_example/node_modules/@angular/router/router.d.ts
    at TsCompilerAotCompilerTypeCheckHostAdapter.fromSummaryFileName (/home/packages/compiler-cli/src/transformers/compiler_host.ts:274:13)
    at AotSummaryResolver.fromSummaryFileName (/execroot/angular/packages/compiler/src/aot/summary_resolver.ts:64:22)
    at /execroot/angular/packages/compiler/src/aot/summary_serializer.ts:441:34
    at Array.map (<anonymous>)
    at FromJsonDeserializer.deserialize (/execroot/angular/packages/compiler/src/aot/summary_serializer.ts:439:33)
    at deserializeSummaries (/execroot/angular/packages/compiler/src/aot/summary_serializer.ts:61:23)
    at AotSummaryResolver._loadSummaryFile (/execroot/angular/packages/compiler/src/aot/summary_resolver.ts:118:13)
    at AotSummaryResolver.resolveSummary (/execroot/angular/packages/compiler/src/aot/summary_resolver.ts:73:12)
    at StaticSymbolResolver._resolveSymbolFromSummary (/execroot/angular/packages/compiler/src/aot/static_symbol_resolver.ts:234:42)
    at StaticSymbolResolver.resolveSymbol (/execroot/angular/packages/compiler/src/aot/static_symbol_resolver.ts:85:36)

Activity

  1. added
    area: core
    area: bazel
    on Jun 14, 2018
  2. added this to the needsTriage milestone on Jun 14, 2018
  3. alexeagle commented on Jun 14, 2018

    @alexeagle
    ContributorAuthor

    @alxhub explains: this router class is the first time we have an @Component inside the @angular packages.

    There's a discrepancy between the generated ngfactory.js

    $ grep EmptyOutletComponentNgFactory node_modules/@angular/router/router.ngfactory.js
    var RouterModuleNgFactory = i0.ɵcmf(i1.RouterModule, [], function (_l) { return i0.ɵmod([i0.ɵmpd(512, i0.ComponentFactoryResolver, i0.ɵCodegenComponentFactoryResolver, [[8, [ɵEmptyOutletComponentNgFactory]], [3, i0.ComponentFactoryResolver], i0.NgModuleRef]), i0.ɵmpd(1073742336, i1.RouterModule, i1.RouterModule, [[2, i1.ɵangular_packages_router_router_a], [2, i1.Router]])]); });
    var ɵEmptyOutletComponentNgFactory = i0.ɵccf("ng-component", i1.ɵEmptyOutletComponent, View_ɵEmptyOutletComponent_Host_0, {}, {}, []);
    exports.ɵEmptyOutletComponentNgFactory = ɵEmptyOutletComponentNgFactory;
    

    and the ngfactory.d.ts

    $ cat node_modules/@angular/router/router.ngfactory.d.ts 
    import * as i0 from '@angular/core';
    import * as i1 from '@angular/router';
    export declare const RouterModuleNgFactory: i0.NgModuleFactory<i1.RouterModule>;
    
  4. alexeagle commented on Jun 14, 2018

    @alexeagle
    ContributorAuthor

    We figure that Bazel angular usage has never worked with components that come from third-party libraries in node_modules.
    We are writing deep imports in the user factory files, like @angular/router/router.ngfactory, and these deep imports don't work with bazel resolution strategy.

    We are in a mixed mode, where we generate commonjs/es5 ngfactory.js files which Rollup won't know how to resolve.

    We could probably find some fix for this, but this doesn't look the same as either google3 or current external, so we are adding complexity. Maybe it is better to fix this by moving all the way to Bazel compilation of libraries from source.

  5. alexeagle commented on Jun 14, 2018

    @alexeagle
    ContributorAuthor

    Another possibility to fix the regression in the short-term by moving this component to some other NgModule in the router package so that user code doesn't generate such an import unless they've opted in.

  6. alexeagle commented on Jun 14, 2018

    @alexeagle
    ContributorAuthor

    @gregmagolan will take a look at making Angular source dependency work in angular-bazel-example, which would give us a principled way to avoid these issues.

  7. gregmagolan commented on Jun 26, 2018

    @gregmagolan
    Contributor

    @alexeagle angular-bazel-example with angular build from source is working with the latest router here: bazel-contrib/rules_nodejs#240. Looks promising. This would resole this issue since the build no longer uses mixed mode (bazel & ngc) for angular. Although in the example, mixed mode is still needed for @ngrx.

  8. mhevery commented on Jun 28, 2018

    @mhevery
    Contributor

    @gregmagolan does that mean we can close this issue?

  9. gregmagolan commented on Jun 28, 2018

    @gregmagolan
    Contributor

    @mhevery Seems like the best way to go to build angular from source. Resolves this issue as well as bazelbuild/rules_typescript#192. Once all the related PRs land then this can get closed. Lets leave it open for now.

  10. mlc-mlapis commented on Jul 4, 2018

    @mlc-mlapis
    Contributor

    @alxhub @alexeagle @gregmagolan ... using Angular "6.1.0-beta.3" and pure ngc compilation produces the following line like var i3 = require("../../node_modules/@angular/router/router.ngfactory"); (in this example in our factory file app.module.ngfactory.js).

    The next bundling step (SystemJS or Rollup, ...) for our app creates a not resolvable dependency in the final code.

    The last correct version of Angular was 6.0.4 and since that time all others have been producing the problem and doesn't allow us to use them ... a real hard break change.

    I suppose that this problem is related how Angular packages are built using Bazel but still don't understand what the comment above means (which / why @Component):

    this router class is the first time we have an @component inside the @angular packages.

    and mainly what is the solution to allow correct compilation of an app using ngc. Can you give us some more explanation?

  11. johnbendi commented on Jul 9, 2018

    @johnbendi

    @mlc-mlapis what @alexeagle means by @Component... is that the @angular/router package didn't previously include that in versions on or prior to 6.0.4 but now it's inclusion is making your build to fail.

  12. mlc-mlapis commented on Jul 9, 2018

    @mlc-mlapis
    Contributor

    @johnbendi ... yep, thanks, you mean the following code in angular/packages/router/src/components/empty_outlet.ts?

    @Component({template: `<router-outlet></router-outlet>`})
    export class EmptyOutletComponent {
    }
    

    Hmm, hard to guess why this is necessary since 6.0.5 and not before.

  13. alexeagle commented on Jul 11, 2018

    @alexeagle
    ContributorAuthor

    EmptyOutletComponent was introduced to fix some other issue - it just so happens no Angular package ever had a Component before. So Bazel users are still stuck on Angular 6.0.4 for now.
    Update on this issue: Greg has all the moving parts to switch to a source dependency on Angular, like we do internally at Google, but it's taking some time to land this work.

  14. mlc-mlapis commented on Jul 12, 2018

    @mlc-mlapis
    Contributor

    @alexeagle ... thanks for the update. Do you think that it is realistic to count with that landing even in 6.1.0 version? It also blocks building paths when using Rollup, SystemJS, ... so no way forward.

  15. alexeagle commented on Jul 17, 2018

    @alexeagle
    ContributorAuthor

    No, 6.1.0 is in RC and will release this week or next (?) so I don't think this will make it.
    I suppose we should reconsider rolling back the EmptyOutletComponent, or somehow excluding that from Bazel builds. @jasonaden any ideas?

  16. jelbourn commented on Jul 18, 2018

    @jelbourn
    Contributor

    It looks like this would also prevent Angular Material from using Angular 6.1 (and thus TypeScript 2.9), since it would break what Bazel stuff we do have working.

  17. gregmagolan commented on Jul 31, 2018

    @gregmagolan
    Contributor

    Example of building angular from source to resolve this issue is here: angular/angular-bazel-example#160

    That still depends on landing bazelbuild/rules_typescript#223 in rules_typescript which includes a work-around which either needs to be finalized or a principled fix in angular/angular put together

  18. danwulff commented on Aug 9, 2018

    @danwulff

    It's very frustrating that Angular projects that utilize Material are unable to use TS 2.9 because of this. Do we have an ETA on when this will get fixed? @alxhub

  19. gregmagolan commented on Aug 10, 2018

    @gregmagolan
    Contributor

    Latest angular can now be build with bazel with angular being built from source. angular/angular-bazel-example#160 was merged in and https://github.com/alexeagle/angular-bazel-example is now building Angular 6.1.2.

    @danwulff: @jelbourn is working on updating Angular Material as well.

  20. mlc-mlapis commented on Aug 10, 2018

    @mlc-mlapis
    Contributor

    @gregmagolan ... I tested Angular 6.1.2 and the problem still persists. Simply using ngc there is generated the line like var i3 = require("../../node_modules/@angular/router/router.ngfactory"); in each module (in its .module.ngfactory.js) which imports @angular/router module. 😢

  21. gregmagolan commented on Aug 10, 2018

    @gregmagolan
    Contributor
  22. mlc-mlapis commented on Aug 10, 2018

    @mlc-mlapis
    Contributor

    @gregmagolan ... not sure if we understand each other but we are using just pure ngc compiler for project AOT compilation, nothing else (sure on the base of installed NPM @angular packages). So no direct Bazel configuration or so ...

  23. gregmagolan commented on Aug 11, 2018

    @gregmagolan
    Contributor

    @mlc-mlapis Oh I see. That would be a different issue from this one. This issue is specific to building Angular with Bazel. Please file a new issue.

  24. mlc-mlapis commented on Aug 11, 2018

    @mlc-mlapis
    Contributor

    @gregmagolan ... Ok, I'll file it. But I think that the main origin of the problem is the same ... the existence of the new code:

    @Component({template: `<router-outlet></router-outlet>`})
    export class EmptyOutletComponent {}
    

    in Router package.

  25. mlc-mlapis commented on Aug 11, 2018

    @mlc-mlapis
    Contributor

    @gregmagolan ... I checked the case once more and we finally found out a way how to configure our build path to accept @Component used even inside Angular packages (because in such cases .ngfactory.js files are produced by ngc compiler). So I won't file a new issue at all.

  26. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  27. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: bazelarea: core

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions