UPDATE: Success! Problem Solved
After much trial and error, I finally discovered the solution to my issue. It turned out that the problem lied in a simple configuration mistake. To rectify this, I made changes to both my package.json (dependencies section) and tsconfig.json files, aligning them with the sample provided on angular.io.
Key modifications included:
- Upgrading angular npm packages from " ~4.0.0" to "~4.2.0"
- Switching the module in tsconfig.json from "system" to "commonjs"
Although I don't entirely comprehend the impact of these alterations, they did the trick!
Original Inquiry
Situation Overview
Our team is working on integrating angular2-jwt into our Angular2/4 project by following the provided configuration example. The setup involves two main files:
app.module.ts
import { AuthConfig, AuthHttp } from 'angular2-jwt';
import { NgModule } from '@angular/core';
import { HttpModule, Http, RequestOptions } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule, routingComponents } from './app.routing';
import { AppComponent } from './Components/app.component';
@NgModule({
imports: [BrowserModule, HttpModule, AppRoutingModule],
declarations: [AppComponent, routingComponents],
bootstrap: [AppComponent],
providers: [
{
provide: AuthHttp,
useFactory: (http: Http, options: RequestOptions) => new AuthHttp(new AuthConfig(), http, options),
deps: [Http, RequestOptions]
}]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
import { AuthHttp } from 'angular2-jwt';
@Component({
selector: "app",
templateUrl: "/App/Components/app.component.html"
})
export class AppComponent
{
constructor(service: AuthHttp)
{ }
}
Error Encountered
Can't resolve all parameters for AppComponent: (?).
Upon examining the constructor of the AuthHttp class (found in the .d.ts file), it became apparent that the likely culprit was the malfunctioning include for AuthConfig
, as attempts to instantiate this class resulted in an error indicating that the constructor was not found.
I stumbled upon a resource suggesting a deeper dive into Dependency Injection (DI), but everything seemed correct from my perspective. https://github.com/auth0/angular2-jwt/issues/88
Update: Additional Insight Uncovered
If the AppComponent
constructor were altered to invoke new AuthConfig()
, it would translate to new angular2_jwt_1.AuthConfig()
in the transpiled js file (resulting in a constructor non-existence error).
However, manually changing this to
new angular2_jwt_1.default.AuthConfig()
in the js file led to successful instance creation. Could this be linked to the root cause?