Skip to content

Error encountered resolving symbol values statically... #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
morphatic opened this issue Dec 22, 2016 · 23 comments
Closed

Error encountered resolving symbol values statically... #258

morphatic opened this issue Dec 22, 2016 · 23 comments
Labels
closed:stale Issue or PR has not seen activity recently question

Comments

@morphatic
Copy link

I just upgraded angular-cli and angular and now I'm getting a compile error when running ng serve:

ERROR in 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
(position 79:22 in the original .ts file), resolving symbol AUTH_PROVIDERS in
/path/to/my/project/node_modules/angular2-jwt/angular2-jwt.d.ts, resolving symbol AppModule in
/path/to/my/project/src/app/app.module.ts, resolving symbol AppModule in
/path/to/my/project/src/app/app.module.ts

BTW, line 79 in angular2-jwt.d.ts reads:

export declare const AUTH_PROVIDERS: Provider[];

I'm using auth0-lock and followed the quickstart tutorial to get up and running.

Workaround 1

It turns out that I don't have any services explicitly using the AuthHttp class, so I just commented out the import { AUTH_PROVIDERS } from 'angular2-jwt'; and providers: [ AUTH_PROVIDERS ] lines from app.module.ts and this seems to fix the issue. Of course, then I have to manually set the Bearer jwt_token value in my Authorization header, but at least it works...

Workaround 2

If I use the alternative configuration approach with provideAuth, I don't get any errors. Here are the relevant bits from my app.module.ts file:

import { NgModule } from '@angular/core';
import { HttpModule, Http, RequestOptions } from '@angular/http';
import { provideAuth, AuthHttp, AuthConfig } from 'angular2-jwt';
import { AppComponent          } from './app.component';
// ... other import statements ...

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp( new AuthConfig({}), http, options);
}

@NgModule({
  declarations: [ AppComponent ],
  imports: [ HttpModule ],
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [ Http, RequestOptions ]
    }
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

Other Info

Here is my current system info:

~$ ng -v
angular-cli: 1.0.0-beta.24
node: 7.0.0
os: darwin x64
@angular/common: 2.4.1
@angular/compiler: 2.4.1
@angular/core: 2.4.1
@angular/forms: 2.4.1
@angular/http: 2.4.1
@angular/platform-browser: 2.4.1
@angular/platform-browser-dynamic: 2.4.1
@angular/router: 3.4.1
@angular/compiler-cli: 2.4.1

I'm using auth0-lock: 10.7.3, angular2-jwt: 0.1.27, and typescript v2.2.0-dev.20161218. Thanks for such great tools!!!

@chenkie
Copy link
Contributor

chenkie commented Dec 22, 2016

Thanks for the info @morphatic, we're looking into that error now.

@fiveone7
Copy link

I've got the same issue.

angular-cli: 1.0.0-beta.22-1
node: 6.9.2
os: win32 x64

@angular/common": "^2.2.3
@angular/compiler": "^2.2.3
@angular/core": "^2.2.3
@angular/forms": "^2.2.3
@angular/http": "^2.2.3
@angular/material": "^2.0.0-alpha.11-3
@angular/platform-browser": "^2.2.3
@angular/platform-browser-dynamic": "^2.2.3
@angular/router": "^3.2.3

angular2-jwt": "^0.1.26
auth0-lock": "^10.7.2

@thehashrocket
Copy link

I think this might be related to this issue.

@nguyenminhtu
Copy link

tks

@the-ult
Copy link

the-ult commented Jan 1, 2017

@chenkie any news on the update to rxjs 5.0x and compatibility with angular 2.4?

@byteofsilicon
Copy link

I am encountering this same issue.

@bkarv
Copy link

bkarv commented Jan 8, 2017

Upgraded to Angular CLI to latest today. I get the same error.

@jonigl
Copy link

jonigl commented Jan 12, 2017

Here I have the same error.

"version": "1.0.0-beta.24"
"angular2-jwt": "^0.1.25"

@escardin
Copy link
Contributor

Try with the newly released 0.1.28. It resolves issues with rxjs versions. I ran the cli and didn't get any compile errors on the project when I ran it, but I don't think I've resolved AOT issues yet. I'm working on getting my large angular project upgraded to latest so I can make sure issues are resolved.

@jonigl
Copy link

jonigl commented Jan 12, 2017

Thanks @escardin I tried the version that you mentioned (0.1.28) but unfortunately I continue with the same error.
I am using the latest version of rxjs.
Now Im using:

"version": "1.0.0-beta.24"
"angular2-jwt": "^0.1.28"
"rxjs": "^5.0.3"

This is my current system info:

angular-cli: 1.0.0-beta.24
node: 6.9.4
os: darwin x64
@angular/common: 2.4.3
@angular/compiler: 2.4.3
@angular/core: 2.4.3
@angular/forms: 2.4.3
@angular/http: 2.4.3
@angular/platform-browser: 2.4.3
@angular/platform-browser-dynamic: 2.4.3
@angular/router: 3.4.3
@angular/compiler-cli: 2.4.3

@thehashrocket
Copy link

Yep, 0.1.28 didn't fix the issue that lead to this error:

ERROR in 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
(position 79:22 in the original .ts file), resolving symbol AUTH_PROVIDERS in
/path/to/my/project/node_modules/angular2-jwt/angular2-jwt.d.ts, resolving symbol AppModule in
/path/to/my/project/src/app/app.module.ts, resolving symbol AppModule in
/path/to/my/project/src/app/app.module.ts

@escardin
Copy link
Contributor

Yeah you can't use AUTH_PROVIDERS with AOT afaik.

@chenkie
Copy link
Contributor

chenkie commented Jan 12, 2017

The snippet above is the way to do it for now until the angular2-jwt @NgModule is ready.

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp( new AuthConfig({}), http, options);
}

@NgModule({
  declarations: [ AppComponent ],
  imports: [ HttpModule ],
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [ Http, RequestOptions ]
    }
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

@memark
Copy link

memark commented Jan 17, 2017

Just FWIW, the problem with AUTH_PROVIDERS is not related (only) to AOT. Even with AOT disabled, angular-cli still does some static analysis, which gives the same error.

@chenkie Any idea when the mentioned @NgModule might be ready?

@escardin
Copy link
Contributor

It's there, you can try it. It's not documented because it's not tested. The additional output from running ngc isn't published either.

@idl-shaohua
Copy link

I ran into this issue too.

    "angular2-jwt": "^0.1.28"
    "angular-cli": "1.0.0-beta.25.5",

    "@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "^3.3.1",

@omarsallah00
Copy link

Thanks @chenkie you have saved my day

@laterbreh
Copy link

I wanted to also comment that I was getting this issue as well using the angular-cli:

"devDependencies": {
    "@angular/cli": "1.0.0-beta.30",
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.3"
  }

and

"angular2-jwt": "^0.1.28"

Was resolved using @morphatic's solutions.

@fiveone7
Copy link

Thank you. -_-

@Kunepro
Copy link

Kunepro commented Mar 23, 2017

Add me to the list.
I got it to work removing AUTH_PROVIDERS like @morphatic suggested, but I would love to have this fixed.

  "devDependencies": {
    "@angular/cli": "^1.0.0-rc.2",
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.3"
  }

@vinicius
Copy link

Thank you, @morphatic ! I was struggling with this issue for hours. I tried the Workaround 2 and it worked well.

@robertsattler
Copy link

Same issue. Thank you @morphatic, Workaround 2 works great.

  "dependencies": {
    "@angular/core": "^4.2.4",
    "angular2-jwt": "^0.2.3",
    // ...
  },
  "devDependencies": {
    "@angular/cli": "1.4.1",

@stale
Copy link

stale bot commented Oct 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Oct 26, 2019
@stale stale bot closed this as completed Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:stale Issue or PR has not seen activity recently question
Projects
None yet
Development

No branches or pull requests