Skip to content

[typescript-angular] Error providing BASE_PATH from NPM module #6730

@martinmcwhorter

Description

@martinmcwhorter
Description

After generating a proxy for typescript-angular as an NPM module, I cannot provide the BASE_PATH without getting the following error:

BASE_PATH Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler (positi on 2:22 in the original .ts file), resolving symbol BASE_PATH

If I include the generated proxy as source typescript within the project, I can provide the BASE_PATH without this error.

Ideally I would like to separate the generated proxy into its own package.

The angular project versions:

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.4.4
node: 6.9.2
os: win32 x64
@angular/animations: 4.4.4
@angular/cdk: 2.0.0-beta.12
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/material: 2.0.0-beta.12
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/cli: 1.4.4
@angular/compiler-cli: 4.4.4
@angular/language-service: 4.4.4
typescript: 2.3.4
Swagger-codegen version

2.3.0-SNAPSHOT

Swagger declaration file content or url
Command line used for generation
$ java -jar swagger-codegen-cli.jar generate -i http://localhost:8080/foo/v2/api-docs -l typescript-angular -o lib/src/foo-proxy -c foo-proxy-config.json
cd lib/src/foo-proxy
yarn build
cd dist
yarn pack
cd ../../../
mv lib/src/foo-proxy/foo-proxy-v0.0.0-SNAPSHOT.201710180947.tgz lib/
yarn install ./lib/foo-proxy-v0.0.0-SNAPSHOT.201710180947.tgz
Steps to reproduce
import { BASE_PATH } from 'foo-proxy';

export function basePath(): string { return '.'; }

@NgModule({
  { provide: BASE_PATH, useFactory: basePath },
  // . . . 
})
export class CoreModule { }

On ng serve I get the reported error:

BASE_PATH Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler (positi on 2:22 in the original .ts file), resolving symbol BASE_PATH

If instead of packaging as a Node Module, I include as source -- I can provide the BASE_PATH without the compile error.

java -jar swagger-codegen-cli.jar generate -i http://localhost:8080/foo/v2/api-docs -l typescript-angular -o src/foo-proxy

Related issues/PRs
Suggest a fix/enhancement

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions