2017-06-09 3 views
1

Wenn ich Angular Material (oder ein anderes Package Format 4.0 Module) importiere, schlägt die AOT-Kompilierung fehl.AOT-Kompilierung schlägt fehl für Angular Material oder Package Format 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 
 
    }; 
 
    } 
 
}

Wenn ich mit AOT die erzeugten ngfactory Dateien für Angular-Material erstellen zyklische Importe kompiliere.

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, 

Dies natürlich bricht den nächsten Schritt des Build-Prozesses. Rollup kann nicht bündeln.

[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'; 

Dies ist in 4.2.0-rc.2 und 4.2.0 repliziert.

Antwort

2

Dies wurde behoben here.

Sie können @angular/compiler und @angular/compiler-cli zu 4.3.0-beta.0 aktualisieren.

jedoch ein neues Problem entdecken ...

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

EDIT

Sie können diese zweite Ausgabe folgen here

0

Dies ist wahrscheinlich ein Bug mit Package Format 4.0, zickeln und ngfactories und ich habe es mit dem Angular-Team eingereicht. Es gibt eine Problemumgehung.

Nachdem Sie ngc ausgeführt haben, finden Sie die ngfactory-Dateien für jede Bibliothek, duplizieren Sie die Datei, benennen Sie sie mit dem Suffix .imports.js um, importieren Sie dann die neue Datei im ursprünglichen ngfactory. Dies wird den zyklischen Import entfernen.

Verwandte Themen