node.js - 当我通过 ng build --prod Angular 4.3.2 部署时出错

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

我已将 Angular 从 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

然后我放置了 ngserve 并运行良好,但是当我想通过 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);

我在网上查了一下这个问题,但没有找到解决的原因。可能缺少什么?

最佳答案

几天后我通过 package.json 中的以下内容解决了 $$_gendir 问题:

  • typescript 版本 2.3.3(“ typescript ”:“~2.3.3”)
  • 脚本/产品:“ng build --env=prod --aot=true”

主要问题是 typescript 版本错误。

关于node.js - 当我通过 ng build --prod Angular 4.3.2 部署时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45449732/

相关文章:

css - Angular CLI 没有 LESS/SASS 的源映射

angular - 在 Angular 中将数据从一个组件发送到另一个组件(已关闭)

node.js - 如何从在 Node 中运行的 webpack 编译的脚本访问运行时环境变量?

mysql - NodeJS MySQL 高级查询

javascript - 如何在nodejs中解析包含环境变量的路径?

node.js - Spotify Web Api - 开始/恢复用户的播放

Angular HttpClient 映射对象的可观察数组

typescript - Angular2,为什么每次移动鼠标时都会调用函数

angular - Angular 2 中的 ng-model 和 NgModel 有区别吗?

angularjs - Jenkins - 构建步骤 'Execute shell' 在 linux 环境中将构建标记为失败