0

When I try to run npm run server I get the error :

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 64:19 in the original .ts file), resolving symbol AppModule in C:/Users/*****/src/app/app.module.ts

webpack: Failed to compile.

Here is the content of my app.module.ts :

    import { NgModule, ApplicationRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {SharedService} from './shared.service';
import { FormsModule } from '@angular/forms';
import {MaskedInput} from './+front/masked-input.directive';

/*
 * Platform and Environment providers/directives/pipes
 */
import { routing } from './app.routing'
// App is our top level component
import { AppComponent } from './app.component';
import { APP_RESOLVER_PROVIDERS } from './app.resolver';
import { AppState, InternalStateType } from './app.service';

// Core providers
import {CoreModule} from "./core/core.module";
import {SmartadminLayoutModule} from "./shared/layout/layout.module";
import {UrlPermission} from "./UrlPermission/urlPermession";
import {Http, HttpModule, RequestOptions, XHRBackend} from '@angular/http';
import {MyCustomHttp} from './interceptor';
import {AuthService} from './AuthService/AuthService';
// Application wide providers
const APP_PROVIDERS = [
  ...APP_RESOLVER_PROVIDERS,
  AppState
];

type StoreType = {
  state: InternalStateType,
  restoreInputValues: () => void,
  disposeOldHosts: () => void
};

/**
 * `AppModule` is the main entry point into Angular2's bootstraping process
 */
@NgModule({
  bootstrap: [ AppComponent ],
  declarations: [
    AppComponent,
  ],
  imports: [ // import Angular's modules
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpModule,
    CoreModule,
    SmartadminLayoutModule,
    routing
  ],
  exports: [
  ],
  providers: [ // expose our Services and Providers into Angular's dependency injection
    // ENV_PROVIDERS,
    APP_PROVIDERS,
    SharedService,
    UrlPermission,
    AuthService,
    MaskedInput,
     {
      provide: Http,
      useFactory: (backend,options) => new MyCustomHttp(backend, options),
      deps: [XHRBackend, RequestOptions]
    },

  ]
})
export class AppModule {
  constructor(public appRef: ApplicationRef, public appState: AppState) {}


}

I thought it was a node version problem so I downgraded NodeJS from 10 version to 8 version. But the error is always the same It worked fine on my old computer. I don't know what changes or what commands should I tape. or how should I change the app.module.ts

Any help please? Thank you

amorino
  • 375
  • 1
  • 3
  • 16
  • I believe your useFactory should be returning a function per https://stackoverflow.com/a/37611614/10747134 Also see: https://angular.io/guide/dependency-injection-providers#factory-providers Since the error line/col is your useFactory implementation. –  Jan 19 '19 at 19:34
  • Can you post the code of `MyCustomHttp`? – Bunyamin Coskuner Jan 19 '19 at 20:16
  • Also, `HttpModule` is deprecated, you should start using `HttpClientModule` – Bunyamin Coskuner Jan 19 '19 at 20:18
  • @BunyaminCoskuner Thank you. Here is the code of `MyCustomHttp` `@Injectable() export class MyCustomHttp extends Http { constructor(_backend: ConnectionBackend, _defaultOptions: RequestOptions) { super(_backend, _defaultOptions); } request(url: string | Request, options?: RequestOptionsArgs): Observable { let token = sessionStorage.getItem('Token'); if(token==null){ token=''; } if (typeof url === 'string') { const headers = new Headers(); headers.append('Authorization', `Bearer ${token}`);` – amorino Jan 20 '19 at 00:35
  • `options = new RequestOptions({headers: headers}); //console.log('Url is string', options.headers.get('Authorization')); } else { url.headers.set('Authorization', `Bearer ${token}`); //console.log('Url is Request', url.headers.get('Authorization')); } return super.request(url, options); } }` – amorino Jan 20 '19 at 00:35
  • Which Angular version are you using? – yurzui Jan 20 '19 at 04:37
  • "version": "4.0.1" – amorino Jan 20 '19 at 04:51

0 Answers0