ng build --prod在HTML上引发属性错误

时间:2019-08-08 09:02:03

标签: angular angular-cli angular-cli-v8

我正在尝试构建Angular 8应用的生产版本,但是我一直在遇到Property '*' does not exist on type '*'错误。

执行的命令:

ng build --prod="true" --verbose=true

收到的错误:

ERROR in src/app/shared/layout/sidenav/sidenav.component.html(1,46): : Property 'always' does not exist on type 'SidenavComponent'.
src/app/shared/layout/sidenav/sidenav.component.html(1,97): : Property 'scrollViewExtras' does not exist on type 'SidenavComponent'.
src/app/shared/layout/sidenav/sidenav.component.html(1,128): : Property 'scrollBarExtras' does not exist on type 'SidenavComponent'.
src/app/shared/layout/sidenav/sidenav.component.html(10,41): : Property 'sidenav' is private and only accessible within class 'SidenavComponent'.

这些是src/app/shared/layout/sidenav/sidenav.component.html的前三行:

<ng-scrollbar class="notice-board-scrollbar" [shown]="always" [compact]="true" [invertY]="true" [viewClass]="scrollViewExtras" [barClass]="scrollBarExtras">
  <cdk-virtual-scroll-viewport ngScrollbarView smoothScroll itemSize="100">
    <mat-list role="list">

如果我构建时没有--prod="true"标志,或者我执行了ng serve,则编译不会出错。

riverman@vscode:~/projects/front$ ng version  

Angular CLI: 8.0.3
Node: 10.16.1
OS: linux x64
Angular: 8.0.2
... animations, cdk, common, compiler, compiler-cli, core
... elements, forms, language-service, platform-browser

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.800.3
@angular-devkit/build-angular       0.800.3
@angular-devkit/build-optimizer     0.800.3
@angular-devkit/build-webpack       0.800.3
@angular-devkit/core                8.0.1
@angular-devkit/schematics          8.0.3
@angular/cli                        8.0.3
@angular/material                   8.0.1
@angular/platform-browser-dynamic   8.0.1
@angular/router                     8.0.1
@ngtools/webpack                    8.0.3
@schematics/angular                 8.0.3
@schematics/update                  0.800.3
rxjs                                6.5.2
typescript                          3.4.5
webpack                             4.30.0

感谢您的任何帮助!

1 个答案:

答案 0 :(得分:2)

我最近遇到过这个问题,希望对我有用的人会有所帮助

在生产配置下更新angular.json

"aot": false, "vendorChunk": true, "buildOptimizer": false,