Skip to content

AOT compilation fails with empty route path from static routes class #17728

Closed

Description

@andreasrueedlinger

I'm submitting a ...


[ ] Regression (behavior that used to work and stopped working in a new release)
[x] Bug report 
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Versions.

@angular/cli: 1.1.3
node: 6.9.1
os: darwin x64
@angular/animations: 4.2.4
@angular/common: 4.2.4
@angular/compiler: 4.2.4
@angular/core: 4.2.4
@angular/flex-layout: 2.0.0-beta.8
@angular/forms: 4.2.4
@angular/http: 4.2.4
@angular/material: 2.0.0-beta.6
@angular/platform-browser: 4.2.4
@angular/platform-browser-dynamic: 4.2.4
@angular/router: 4.2.4
@angular/cli: 1.1.3
@angular/compiler-cli: 4.2.4

Current behavior

We have a routes class which holds all the static routes strings to be used in routes configuration of angular and in all the router links:

export class RoutesPathRegistry {
  static foo = '';
  static bar = 'link'; 
}

Using this link in the routes setup breaks the AOT compilation with angular CLI:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { RoutesPathRegistry } from 'app/modules/routes';
import { FooComponent } from './components/foo.component';
import { BarComponent } from './components/bar.component';

const appRoutes: Routes = [
  {
    path: RoutesPathRegistry.bar,
    component: BarComponent
  },
  {
    path: RoutesPathRegistry.foo,
    component: FooComponent,
    pathMatch: 'full'
  }
];

@NgModule({
  imports: [
    RouterModule.forRoot(appRoutes)
  ],
  exports: [
    RouterModule
  ]
})
export class AppRoutingModule {}

AOT compilation with the error:

ERROR in Illegal state: symbol without members expected, but got {"filePath":"****/src/app/modules/routes/path-registry.ts","name":"RoutesPathRegistry","members":["foo"]}.

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '****/src'
 @ ./src/main.ts 3:0-74
 @ multi ./src/main.ts

Expected behavior

Successful AOT compilation

Activity

  1. added
    area: core
    on Jun 23, 2017
  2. krishnanmk commented on Jul 1, 2017

    @krishnanmk

    @andreasrueedlinger , I think the issues we posted earlier in angular-cli are similar (6782 and 6784). Essentially, we are using two variables to finally prepare our routes object.

    Angular peeps, here is another dead-simple scenario to reproduce the issue.

    const appRoutes = [...]; // I define some routes here
    const newRoutes = appRoutes; // a dead simple referencing
    
    @NgModule({
      imports: [RouterModule.forRoot(appRoutes)] // this works
      ...
      imports: [RouterModule.forRoot(newRoutes)] // this does NOT work
    })
    ...
    

    If you notice, in the second scenario, the prod bundle file will not have the variable definitions in it at all.

    Hope this gets resolved soon. Waiting for this to release my app on production.

  3. krishnanmk commented on Jul 6, 2017

    @krishnanmk

    Angular people, any updates?

  4. added this to the Backlog milestone on Jan 23, 2018
  5. sgehrman commented on Jun 26, 2018

    @sgehrman

    Still looking for a solution to this... Anyone?

  6. added
    area: compiler
    and removed
    area: core
    on Mar 12, 2020
  7. JoostK commented on Mar 14, 2020

    @JoostK
    Member

    Hello folks,

    In ViewEngine, the AOT compiler needed to know everything about code that was referenced from Angular decorators. Now with Ivy, this is no longer the case; when the compiler doesn't need to know about some metadata in a decorator, it simply includes the user's code in the compilation output without the need to statically interpret it. Note that there are still places where the compiler does need to statically interpret data, so some constraints still apply.

    Because of this change, this issue is no longer a problem with Ivy.

  8. krishnanmk commented on Mar 15, 2020

    @krishnanmk

    For people who have not moved to Angular 9/Ivy, I think the following hack might just work. Whatever your variable/object/function is, try export it. It worked for me in one case. Hope it does for you guys too.

  9. angular-automatic-lock-bot commented on Apr 15, 2020

    @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.

  10. locked and limited conversation to collaborators on Apr 15, 2020
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

    area: compilerarea: routerfreq2: mediumtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions