使用--prod开关构建时Angular2 / Angular-cli奇怪的错误

时间:2017-03-16 07:26:10

标签: angular angular-cli

我最近将angular-cli更新为1.0.0-rc2并且似乎一切顺利,但我无法使用--prod开关构建我的应用程序。我正在使用ng2-spin-kit模块来加载指示器,并且一直抱怨无法找到ng-2-spin-kit模块的每个组件的模块。知道这里可能出现什么问题吗?我怎么能解决这个问题?

更新

因此事实证明,最新版本的angular-cli默认情况下将--aot(提前编译)标志设置为true,并且我的一些组件未针对编译进行优化。任何想法如何更新我的所有组件以便提前接受编译?我不是指ng2-spin-kit。只是我的应用程序特定组件,事实证明我的大多数组件都经过优化,即使我没有打算在编写它们时... ...

my app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule, Routes } from '@angular/router';
import { CircleComponent } from './components/loader/spinner/circle.component';


import { AppComponent } from './app.component';
import { ProductComponent } from './Components/product/product.component';

import { CheckBarcodesComponent } from './Components/check-barcodes/check-barcodes.component';
import { HomeComponent } from './Components/home/home.component';
import { NavigationComponent } from './Components/navigation/navigation.component';
import { SettingsComponent } from './Components/settings/settings.component';
import { StockTransactionItemComponent } from './Components/stock-transaction-item/stock-transaction-item.component';
import { StockTakeComponent } from './Components/stock-take/stock-take.component';
import { LoaderComponent } from './Components/loader/loader.component';
import { ErrorComponent } from './Components/error/error.component';
import { GoodsReceivedComponent } from './components/goods-received/goods-received.component';
import { LoginComponent } from './components/login/login.component';

import { RestService } from './services/rest.service';
import { LocalStorageService } from './services/local-storage.service';
import { UserService } from './services/user.service';

import { AppRoutingModule } from './app.routing';
import { StatusComponent } from './Components/status/status.component';
import { StringToDatePipe } from './pipes/string-to-date.pipe';



@NgModule({
  declarations: [
    AppComponent,
    ProductComponent,
    CheckBarcodesComponent,
    HomeComponent,
    NavigationComponent,
    SettingsComponent,
    StockTransactionItemComponent,
    StockTakeComponent,
    CircleComponent,
    LoaderComponent,
    GoodsReceivedComponent,
    ErrorComponent,
    StatusComponent,
    LoginComponent,
    StringToDatePipe    
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    AppRoutingModule
  ],
  providers: [
    RestService,
    LocalStorageService,
    UserService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

ng2-spin-kit:https://www.npmjs.com/package/ng2-spin-kit

我的错误/输出:

   {0} polyfills.34c267ddff87908e0732.bundle.js (polyfills) 157 kB {5} [initial] [rendered]
chunk    {1} main.8abb16adf25a257394ee.bundle.js (main) 534 kB {4} [initial] [rendered]
chunk    {2} scripts.dde47148c4c3cb36c6df.bundle.js (scripts) 226 kB {5} [initial] [rendered]
chunk    {3} styles.7c25a02a137df81c1ced.bundle.css (styles) 122 bytes {5} [initial] [rendered]
chunk    {4} vendor.608820e6096d2310322a.bundle.js (vendor) 2.46 MB [initial] [rendered]
chunk    {5} inline.077315b77d1f4e6e0707.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in ./src/$$_gendir/app/components/login/login.component.ngfactory.ts
Module not found: Error: Can't resolve '../loader/loader.component.ngfactory' in 'C:\Users\Deon\Documents\trade-link\rtm\src\$$_gendir\app\components\login'
 @ ./src/$$_gendir/app/components/login/login.component.ngfactory.ts 26:0-65
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./src/$$_gendir/app/components/login/login.component.ngfactory.ts
Module not found: Error: Can't resolve '../error/error.component.ngfactory' in 'C:\Users\Deon\Documents\trade-link\rtm\src\$$_gendir\app\components\login'
 @ ./src/$$_gendir/app/components/login/login.component.ngfactory.ts 29:0-63
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./src/$$_gendir/app/components/goods-received/goods-received.component.ngfactory.ts
Module not found: Error: Can't resolve '../error/error.component.ngfactory' in 'C:\Users\Deon\Documents\trade-link\rtm\src\$$_gendir\app\components\goods-received'
 @ ./src/$$_gendir/app/components/goods-received/goods-received.component.ngfactory.ts 45:0-63
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./src/$$_gendir/app/components/login/login.component.ngfactory.ts
Module not found: Error: Can't resolve '../navigation/navigation.component.ngfactory' in 'C:\Users\Deon\Documents\trade-link\rtm\src\$$_gendir\app\components\login'
 @ ./src/$$_gendir/app/components/login/login.component.ngfactory.ts 44:0-73
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./src/$$_gendir/app/components/goods-received/goods-received.component.ngfactory.ts
Module not found: Error: Can't resolve '../navigation/navigation.component.ngfactory' in 'C:\Users\Deon\Documents\trade-link\rtm\src\$$_gendir\app\components\goods-received'
 @ ./src/$$_gendir/app/components/goods-received/goods-received.component.ngfactory.ts 47:0-73
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./src/$$_gendir/app/Components/loader/loader.component.ngfactory.ts
Module not found: Error: Can't resolve './spinner/circle.component.ngfactory' in 'C:\Users\Deon\Documents\trade-link\rtm\src\$$_gendir\app\Components\loader'
 @ ./src/$$_gendir/app/Components/loader/loader.component.ngfactory.ts 22:0-65
 @ ./src/$$_gendir/app/Components/settings/settings.component.ngfactory.ts
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

C:\Users\Deon\Documents\trade-link\rtm>

1 个答案:

答案 0 :(得分:0)

实际上,在正常情况下,'Component'不需要任何特殊的东西来支持aot,但模块需要。出错的原因是您使用的模块ng2-spin-kit不支持AOT。您可以看到此issue来说出有关AOT的错误。

您可以更新该旋转模块。关于如何支持AOT,您可以查看this