Error detecting character value values ​​statically

Our Angular 2 app has a build error, but only when using "ng build -prod", not when using "ng build" or "ng serve". Error message:

ERROR in Error encountered resolving symbol values statically. Expression form not supported (position 27:55 in the original .ts file), resolving symbol RestService in [...]/src/app/shared-modules/service/rest/rest.service.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\LPROG\Ldev\Projekte\svn\hippo_branch\frontend\shared\src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

      

The related piece of code is this:

    constructor(
      private http: Http,
      private mappingService: MappingService,
      private backendUrlService: BackendUrlService,
      @Inject('RestServiceConfig') public config: {rest_api_name: string}) {

      

I can change it to this:

    constructor(
      private http: Http,
      private mappingService: MappingService,
      private backendUrlService: BackendUrlService,
      @Inject('RestServiceConfig') public config: any) {

      

This works with "ng build -prod" and I think we can live with this change (although I still have other bugs, they shouldn't be related), but I'm wondering why this is so and would like to have strong typing. Can someone explain this to me?

ng -v
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0-rc.1
node: 6.9.4
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.10

      

+3


source to share


1 answer


The reason you get an error when using ng build --prod

is because this command also implies a switch --aot

.

Angular Forward compilation time requires your code to be statistically analyzed. The payoff is a significant reduction in the package size. I suggest you modify your code as follows, which gives you strong typing and AOT work. And the type is reusable:



// Before your class
export interface Config {
  rest_api_name: string;
}

// In your class
constructor(
  private http: Http,
  private mappingService: MappingService,
  private backendUrlService: BackendUrlService,
  @Inject('RestServiceConfig') public config: Config) {

      

0


source







All Articles