建立角4生产项目

问题描述:

我正在从事角4项目。 当我运行“NG建立-prod -aot =假”,以建立生产项目,我有错误讯息,你可以看到如下:建立角4生产项目

时间:44075ms 块{0} polyfills.d8674538798840c67825.bundle.js( polyfills)252 kB {5} [initial] [rendered] chunk {1} main.2d2d57386cb503360e3d.bundle.js(main)72 kB {4} [initial] [rendered] chunk {2} scripts.d0a13d2099c21c77943a.bundle。 js(scripts)410 kB {5} [initial] [rendered] chunk {3} styles.aef7beffbbfb61f4f445.bundle.css(styles)175 bytes {5} [initial] [rendered] chunk {4} vendor.e29287b60dbca26b1047。 bundle.js(vendor)3.43 MB [initial] [rendered] chunk {5} inline.6266454082b265a77bf0.bundle.js(inline)0 bytes [entry] [r已排列]

“遇到错误时遇到静态解析符号值。函数调用不受支持。考虑使用对导出函数的引用替换函数或lambda(原始.ts文件中的位置66:27),解析C中的符号AppModule:/Ashirama_workspace/angularproject/src/app/app.module.ts“

这里是我的app.modu.ts文件:

import { NgModule } from '@angular/core'; 
    import { FormsModule,ReactiveFormsModule } from '@angular/forms'; 
    import {NgForm} from '@angular/forms'; 
    import { Http, HttpModule } from '@angular/http'; 
    import { HttpClientModule } from '@angular/common/http'; 
    import { BrowserModule } from '@angular/platform-browser'; 
    import { BrowserAnimationsModule } from '@angular/platform- 
    browser/animations'; 
    import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; 
    import { TranslateHttpLoader } from '@ngx-translate/http-loader'; 
    import { AppRoutingModule } from './app-routing.module'; 
    import { AppComponent } from './app.component'; 
    import { AuthGuard } from './shared/'; 
    import {Guards}from './guards/guards'; 
    import {AuthenticationService} from 
    "./services/authentification.service"; 
    import {UserService} from "./services/user.service"; 
    import {HttpService} from "./services/http.service"; 
    import {LoginComponent} from './login/login.component'; 
    import { AuthHttp, AuthConfig, AUTH_PROVIDERS, provideAuth } from 
    'angular2-jwt'; 
    import {ToastModule} from 'ng2-toastr/ng2-toastr'; 
    import { ToastrModule } from 'ngx-toastr'; 
    import { AlertModule } from 'ngx-bootstrap/alert'; 
    import { Ng2BootstrapModule } from 'ngx-bootstrap/ng2-bootstrap'; 

    // AoT requires an exported function for factories 
    export function HttpLoaderFactory(http: Http) { 
    // for development 
    return new TranslateHttpLoader(http, '/assets/i18n/', '.json'); 
    } 
    @NgModule({ 
     declarations: [ 
     AppComponent 

    ], 
    imports: [ 
    BrowserModule, 
    BrowserAnimationsModule, 
    FormsModule, 
    ReactiveFormsModule, 
    HttpModule, 
    HttpClientModule, 
    AppRoutingModule, 
    ToastModule.forRoot(), 
    ToastrModule.forRoot(), 
    AlertModule.forRoot(), 
    Ng2BootstrapModule, 
    TranslateModule.forRoot({ 
     loader: { 
      provide: TranslateLoader, 
      useFactory: HttpLoaderFactory, 
      deps: [Http] 
      } 
     }) 
     ], 
    providers: [ 
    AuthGuard, 
    AuthenticationService, 
    UserService, 
    HttpService, 
    Guards, 
    AuthHttp, 
    provideAuth({ 
     headerName: 'Authorization', 
     headerPrefix: 'Bearer', 
     tokenName: 'id_token', 
     tokenGetter: (() => localStorage.getItem('id_token')), 
     globalHeaders: [{ 'Content-Type': 'application/json' }], 
     noJwtError: true 
    }) 


    ], 
    bootstrap: [AppComponent] 
     }) 
     export class AppModule { 
     } 

请让我知道什么我'做错了谢谢

+0

可您发布'应用.module.ts'或者你曾经有过lambda函数('()=> function')的地方? – Moema

+0

它已完成我更新我的帖子与app.modulte.ts包含文件作为您的问。 –

+0

让我说,我使用的大部分功能是服务,看起来像登录(用户名:字符串,密码:字符串):Observable {} –

你有你的lambda函数() => something转换为输出功能像

export function doSomething() { 
    .... 
} 

this Github post了更详细的说明。

编辑:

你的情况,你必须更换provideAuthAuthHttp与工厂方法:

export function getAuthHttp(http) { 
    return new AuthHttp(new AuthConfig({ 
    headerName: 'Authorization', 
    headerPrefix: 'Bearer', 
    tokenName: 'id_token', 
    tokenGetter: (() => localStorage.getItem('id_token')), 
    globalHeaders: [{ 'Content-Type': 'application/json' }], 
    noJwtError: true 
    }), http); 
} 

然后

providers: [ 
    { 
     provide: AuthHttp, 
     useFactory: getAuthHttp, 
     deps: [Http] 
    }, 
+0

我只是尝试你的建议,但错误仍然出现 –

+0

你能否用引发错误的代码更新你的文章? – Moema

+0

它已完成我更新我的帖子作为你的问题。 –

它看起来像树摇晃是没有发生正常的角度CLI 1.4及其解决。 .x,但如果您使用的是先前版本的角度cli,则可以添加反射元数据并再次尝试编译。

npm install -save reflect-metadata

+0

谢谢你的回答,但错误仍然存​​在 –