swagger-api / swagger-api/swagger-codegen

[typescript-angular] Error providing BASE_PATH from NPM module

Open
#6,730 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated typescript-angular package produced by the listed swagger-codegen command, then inspect how BASE_PATH is exported and consumed after yarn pack and installation. Compare that package with the same generated files included as source and reproduce the Angular compiler error during ng serve. Done means an installed package can provide BASE_PATH through the shown Angular module configuration without the static-resolution error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, node.js, typescript
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.