使用Ahead-of-time编译构建Angular应用程序时发出警告

时间:2017-03-18 11:54:41

标签: angular angular-cli angular2-aot

我在最近的项目中使用angular-cli。构建开发工作按预期工作,但使用ng build --prod构建生产时会输出以下警告:

  警告在./src/$$_gendir/app/app.module.ngfactory.ts中   498:95-110" export' string' (导入为' import34')未找到   ' ../../应用程序/ api.service'

结果,应用程序不会运行。感谢R. Richards的评论,结果发现这个警告是由使用angular-cli构建生产时的提前编译引起的。

我的ApiService看起来像这样:

import {Injectable, Optional} from '@angular/core';
import {
  Http, Headers, Response, URLSearchParams, RequestOptionsArgs, RequestOptions,
  RequestMethod
} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import {Item} from './models/item';

@Injectable()
export class ApiService {
    constructor(protected http: Http, @Optional() protected basePath: string)       {
      if (basePath) {
          this.basePath = basePath;
      }
      this.http = http;
    }

    //...
}

更详细地研究这一点表明此警告是由可选的依赖注入(@Optional() protected basePath: string)引起的。删除它会导致使用正在运行的应用程序进行无警告构建。

0 个答案:

没有答案