Skip to content

[ANGULAR-TYPSCRIPT] Error during template compile of 'SwaggerModule' Only initialized variables and constants can be referenced in decorators because the value of this variable is needed by the template compiler in 'BASE_PATH' 'BASE_PATH' references 'BASE_PATH' 'BASE_PATH' is not initialized at #8106

Description

@OkeTennie1
Description

We generate an Typscripte Api client for Angular with this Mavenplugin https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin . After that we publish the generated client code to a private npm repro. Then we integrate it into an Angular project and embed like in this tutorial: https://angular.schule/blog/2018-04-swagger-codegen .

after building the project with the folowing command
ng serve --prod

We get the follwing error:

Error during template compile of 'SwaggerModule' Only initialized variables and constants can be referenced in decorators because the value of this variable is needed by the template compiler in 'BASE_PATH' 'BASE_PATH' references 'BASE_PATH' 'BASE_PATH' is not initialized at ..

ng serve without production works totaly fine.

Swagger-codegen version

2.31

Swagger declaration file content or url
Command line used for generation
<language>typescript-angular</language> 
<output>...</output>                               
<configOptions>
         <packageName>labcom.agriportal</packageName>
          <npmName>@swagger/AgriportalProxy</npmName>
          <npmVersion>0.0.4</npmVersion>
          <snapshot>true</snapshot>    
          <ngVersion>5.2.10</ngVersion>
          <npmRepository>... </npmRepository>
</configOptions>

Steps to reproduce
  1. generate Typscript Api Client for Angular 5.2.10
  2. publish to npm
  3. import it into an plain angular project
  4. Set BASE_PATH in the AppModule like:
    import { ApiModule, BASE_PATH } from 'swaggerPackage ... providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }], '
  5. Build project in production mode with:
    ng serve --prod
Related issues/PRs
Suggest a fix/enhancement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions