通过ng build部署时出错--prod Angular 4.3.2

时间:2017-08-02 00:46:23

标签: node.js angular angular-cli npm-install

我已将角度从4.0.0升级到4.3.2:

npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest rxjs@latest --save

然后我放ng serve并且运行良好但是当我想要ng build --prod部署时,我有以下错误:

[1m[33mWARNING in ./src/$$_gendir/app/app.module.ngfactory.ts
730:2-27 "export 'ɵNgModuleInjector' (imported as 'import0') was not found in '@angular/core'[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (11,49): Property 'ɵNgModuleInjector' does not exist on type 'typeof "C:/Data/angular4/system/node_modules/@angular/core/core"'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (41,79): Property 'parent' does not exist on type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (45,76): Property 'parent' does not exist on type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (46,38): Property 'parent' does not exist on type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (46,70): Property 'parent' does not exist on type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (46,99): Argument of type 'this' is not assignable to parameter of type 'Injector'.
  Type 'ApplicationModuleInjector' is not assignable to type 'Injector'.
    Property 'get' is missing in type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (46,109): Property 'parent' does not exist on type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (46,147): Property 'componentFactoryResolver' does not exist on type 'ApplicationModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/core/core.ngfactory.ts (67,94): Cannot create an instance of the abstract class 'NgModuleFactory'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/common/common.ngfactory.ts (11,44): Property 'ɵNgModuleInjector' does not exist on type 'typeof "C:/Data/angular4/system/node_modules/@angular/core/core"'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/common/common.ngfactory.ts (18,111): Property 'parent' does not exist on type 'CommonModuleInjector'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/common/common.ngfactory.ts (33,84): Cannot create an instance of the abstract class 'NgModuleFactory'.[39m[22m

[1m[31mERROR in C:/Data/angular4/system/src/$$_gendir/node_modules/@angular/platform-browser/platform-browser.ngfactory.ts (12,45): Property 'ɵNgModuleInjector' does not exist on type 'typeof "C:/Data/angular4/system/node_modules/@angular/core/core"'.[39m[22m

我还要显示文件内容:main.ts

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
  enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);

我在互联网上查询此事但我找不到解决的理由。它会丢失什么?

1 个答案:

答案 0 :(得分:1)

我在package.json中使用以下内容解决了$$ _ gendir问题:

  • 打字稿版本2.3.3(“打字稿”:“~2.3.3”)
  • script / prod:“ng build --env = prod --aot = true”

主要问题是错误的打字稿版本。