question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AOT compilation fails with empty route path from static routes class

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
sgehrmancommented, Jun 26, 2018

Still looking for a solution to this… Anyone?

1reaction
JoostKcommented, Mar 14, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular2 routing - Angular 2 AOT Compilation Error - New Instance ...
I've implemented a RouteConfigBuilder for my specific purpose clear the routes declarations with custom variables. route-builder.type.ts export class ...
Read more >
Route - Angular
Empty -path route configurations can be used to instantiate components that do not 'consume' any URL segments. In the following configuration, when navigating...
Read more >
An Introduction to Component Routing with Angular Router
It is a tree of routes, defined as a JavaScript array, where each route can have the following properties: path: string, path to...
Read more >
Lazy-loading Feature Modules - Angular - W3cubDocs
In the lazy-loaded module's routing module, add a route for the component. const routes: Routes = [ { path: '', component: ItemsComponent }...
Read more >
Angular 2 - Routing - DevTut
ResolveData, Routing with Children, Basic Routing, Child Routes. ... class Route { path : string pathMatch : 'full'|'prefix' component : Type|string .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found