[英]AOT compile fails for Angular Material or Package Format 4.0
When I import Angular Material (or any other Package Format 4.0 Modules), AOT compile fails. 当我导入Angular Material(或任何其他Package Format 4.0模块)时,AOT编译失败。
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 }; } }
When I compile with AOT the generated ngfactory
files for Angular Material create cyclical imports. 当我用AOT编译时,为Angular Material生成的
ngfactory
文件会创建周期性导入。
index.ngfactory.ts 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,
This of course breaks the next step of the build process. 当然,这中断了构建过程的下一步。 Rollup can't bundle.
汇总无法捆绑。
[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';
This is replicated in 4.2.0-rc.2
and 4.2.0
. 这在
4.2.0-rc.2
和4.2.0
复制。
This has been fixed here . 这已在此处修复。
You can update @angular/compiler
and @angular/compiler-cli
to 4.3.0-beta.0
. 您可以将
@angular/compiler
和@angular/compiler-cli
为4.3.0-beta.0
。
However you will discover a new issue... 但是,您会发现一个新问题...
(function (exports, require, module, __filename, __dirname) { import * as i0 from '@angular/core';
SyntaxError: Unexpected token import
EDIT 编辑
This is most likely a bug with Package Format 4.0, tsickle and ngfactories and I have filed it with the Angular team. 这很可能是Package Format 4.0,tsickle和ngfactories的错误,我已将其提交给Angular团队。 There is a workaround.
有一种解决方法。
After running ngc, find the ngfactory files for each library, duplicate the file, rename it with the suffix .imports.js then in the original ngfactory import the new file. 运行ngc之后,找到每个库的ngfactory文件,复制该文件,并使用后缀.imports.js重命名,然后在原始ngfactory中导入新文件。 This will remove the cyclical import.
这将删除周期性导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.