2017-06-09 93 views
1

當我導入Angular材料(或任何其他包格式4.0模塊)時,AOT編譯失敗。AOT編譯失敗的角度材料或包格式4.0

import { NgModule, ModuleWithProviders } from '@angular/core'; 
 
import {MdButtonModule, MdCheckboxModule} from '@angular/material'; 
 

 
@NgModule({ 
 
    imports:  [ 
 
        MdButtonModule, 
 
        MdCheckboxModule 
 
       ], 
 
    exports:  [ 
 
        MdButtonModule, 
 
        MdCheckboxModule 
 
       ] 
 
}) 
 

 
export class NorSharedModule { 
 
    static forRoot(): ModuleWithProviders { 
 
    return { 
 
     ngModule: NorSharedModule 
 
    }; 
 
    } 
 
}

當我與AOT編譯生成的ngfactory文件角材質打造循環進口。

index.ngfactory.ts

/** 
* @fileoverview This file is generated by the Angular template compiler. 
* Do not edit. 
* @suppress {suspiciousCode,uselessCode,missingProperties,missingOverride} 
*/ 
/* tslint:disable */ 

import * as i0 from '@angular/core'; 
import * as i1 from '@angular/material'; 
import * as i2 from '@angular/common'; 
import * as i3 from '@angular/platform-browser'; 
import * as i4 from './index.ngfactory'; 
import * as i5 from '@angular/forms'; 
import * as i6 from '@angular/http'; 
export const MdCoreModuleNgFactory:i0.NgModuleFactory<i1.MdCoreModule> = i0.ɵcmf(i1.MdCoreModule, 

當然,這打破了構建過程的下一個步驟。彙總不能捆綁。

[8:51:38] LOG ngc started compiling ngfactory 
[8:51:50] LOG ngc compiled /ngfactory 
[8:51:50] LOG Rollup started bundling ngfactory 
Error: A module cannot import itself 
ngfactory/node_modules/@angular/material/typings/index.ngfactory.js (5:0) 
3: import * as i2 from '@angular/common'; 
4: import * as i3 from '@angular/platform-browser'; 
5: import * as i4 from './index.ngfactory'; 
^
6: import * as i5 from '@angular/forms'; 
7: import * as i6 from '@angular/http'; 

這在4.2.0-rc.24.2.0複製。

回答

2

已修復此問題here

您可以將@angular/compiler@angular/compiler-cli更新爲4.3.0-beta.0

但是你會發現一個新的問題......

(function (exports, require, module, __filename, __dirname) { import * as i0 from '@angular/core'; 
SyntaxError: Unexpected token import 

編輯

您可以按照第二個問題here

0

這很可能是包格式4.0,tsickle和ngfactories的一個錯誤,我已經將其與Angular團隊歸檔。有一個解決方法。

運行ngc後,找到每個庫的ngfactory文件,複製文件,用後綴.imports.js重命名,然後在原始的ngfactory中重新導入新文件。這將消除週期性的進口。