Skip to content

Adding RouterModule breaks Ivy apps using platformBrowserDynamic #27794

Closed

Description

@alan-agius4

🐞 bug report

Affected Package

StaticInjector in @angular/core

Description

When adding the RouterModule and use ngtsc, together with the usual platformBrowserDynamic bootstrapping code causes a runtime error.

🔬 Minimal Reproduction

git clone https://github.com/alan-agius4/ivy-router-issue.git
npm i
node_modules\.bin\ivy-ngcc
ng serve --prod

🔥 Exception or Error

Runtime error:

core.js:15268 ERROR TypeError: Cannot read property '__source' of undefined
    at t.get (core.js:8532)
    at t.get (core.js:8894)
    at core.js:1207
    at Ne (core.js:1207)
    at Object.t_Factory [as factory] (ngInjectableDef.js:8)
    at t.hydrate (core.js:9017)
    at t.get (core.js:8888)
    at core.js:1207
    at Ne (core.js:1207)
    at Fe (core.js:1264)

🌍 Your Environment

Angular Version:

Angular CLI: 7.2.0-rc.0
Node: 11.0.0
OS: win32 x64
Angular: 7.2.0-rc.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.0-rc.0
@angular-devkit/build-angular     0.12.0-rc.0
@angular-devkit/build-optimizer   0.12.0-rc.0
@angular-devkit/build-webpack     0.12.0-rc.0
@angular-devkit/core              7.2.0-rc.0
@angular-devkit/schematics        7.2.0-rc.0
@ngtools/webpack                  7.2.0-rc.0
@schematics/angular               7.2.0-rc.0
@schematics/update                0.12.0-rc.0
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.23.1

Anything else relevant?
At first glace, it doesn't look like this is a CLI issue as disabling Optimizations and Build Optimizer, yields the same result.

Activity

  1. added this to the needsTriage milestone on Dec 21, 2018
  2. alexzuza commented on Jan 1, 2019

    @alexzuza
    Contributor

    Looks like ngcc issue since it can't transform _decorate statement from Location to Location.ngInjectableDef due to the fact that Location class contains static methods that result in

    fesm5/common.js

    Location = Location_1 = __decorate([
            Injectable(),
    

    And ngcc compiler is trying to recognize it as follows:

    ngcc

    Update:

    Apparently @petebacondarwin has already caught similar problem here #27841 (comment)

    Update 2:

    Forgot to mention that we can still be able to start ivy application with RouterModule.

    For that we have to either:

    • include Reflect in polifills.ts
    import 'core-js/es7/reflect';
    
    • or change target from es5 to es2015 in tsconfig.json

    Update 3:

    Should be fixed by #27848

  3. angular-automatic-lock-bot commented on Sep 14, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions