如何在AngularCLI rc.1上进行生产构建?

时间:2017-03-13 21:05:41

标签: angularjs typescript angular-cli typescript2.0

按照维基上的升级说明后,我刚刚更新到angular-cli 1.0.0-rc1。

当我运行ng serve时 - 该应用行为正常。

当我运行ng build时 - 该应用行为正常。

当我运行ng build --target=production --environment=prod时 我得到以下内容:

➜  web git:(master) ✗ ng build --target=production --environment=prod
Hash: 1e69750dbc9679bddab0
Time: 69052ms
chunk    {0} main.8839163bd6c77300ac2a.bundle.js (main) 1.11 MB {3} [initial] [rendered]
chunk    {1} styles.014a26b5c21b6bdedf9e.bundle.css (styles) 440 bytes {4} [initial] [rendered]
chunk    {2} scripts.73c5e350c283a9340ddc.bundle.js (scripts) 146 kB {4} [initial] [rendered]
chunk    {3} vendor.f208e8b0304d6a96ac3d.bundle.js (vendor) 2.54 MB [initial] [rendered]
chunk    {4} inline.1eab99acff53ba884df2.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in ../api/src/business/dtos/modifier.dto.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:6768:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80500:23)
    at IdentifierObject.TokenOrIdentifierObject.getText (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80521:77)
    at refactor.findAstNodes.filter (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:129:10)
    at Promise.resolve.then (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:292:33)
 @ ./src/app/model-labels/model-label.component.ts 3:0-51
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ../api/src/business/dtos/document.dto.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:6768:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80500:23)
    at IdentifierObject.TokenOrIdentifierObject.getText (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80521:77)
    at refactor.findAstNodes.filter (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:129:10)
    at Promise.resolve.then (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:292:33)
 @ ./src/app/document-viewer/document-viewer.component.ts 2:0-51
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ../api/src/business/dtos/models.dto.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:6768:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80500:23)
    at IdentifierObject.TokenOrIdentifierObject.getText (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80521:77)
    at refactor.findAstNodes.filter (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:129:10)
    at Promise.resolve.then (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:292:33)
 @ ./src/app/model-sublabel/model-sublabel.component.ts 1:0-46
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ../api/src/business/dtos/lens.dto.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:6768:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80500:23)
    at IdentifierObject.TokenOrIdentifierObject.getText (/Users/jmurphy/projects/business/web/node_modules/typescript/lib/typescript.js:80521:77)
    at refactor.findAstNodes.filter (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:129:10)
    at Promise.resolve.then (/Users/jmurphy/projects/business/web/node_modules/@ngtools/webpack/src/loader.js:292:33)
 @ ./src/app/create-lens/create-lens.component.ts 2:0-43
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in main.8839163bd6c77300ac2a.bundle.js from UglifyJs
Unexpected token: name (FooterComponent) [main.8839163bd6c77300ac2a.bundle.js:7,6]

如何让我的应用程序正确编译以进行制作?

更新1: 以下是其中一个违规文件的示例。 ColumnTypes.TEXT是一个公共值。由于这些只是装饰器,因此它们没有外部依赖关系。同样,这适用于非生产版本。

import {autoserialize} from "cerialize";
import {ManyToOne, PrimaryGeneratedColumn, Column, JoinColumn, OneToOne, OneToMany, Table, ColumnTypes, CreateDateColumn} from "./export.dtos";

@Table()
export class DTOModifier {

  @PrimaryGeneratedColumn()
  @autoserialize id: number;

  @Column(ColumnTypes.TEXT, {nullable: true})
  @autoserialize label: string;
}

其中:

static TEXT: ColumnType;

1 个答案:

答案 0 :(得分:0)

使用angluar-cli进行生产构建时> beta.27(我认为它是beta 27),你暗中使用了提前编译。

提前编译仅在您从模板访问的组件成员是公共的时才有效。您似乎有一个组件,其中某个类成员text设置为私有。

原因是,ngc(角度编译器)将从模板中生成常规的typescript-class,并且在尝试编译此文件时,临时模板类无法访问私有组件成员。

修改

我不是100%确定这实际上是你的问题,但这是我在开始制作生产时遇到的问题,而你可能有同样的问题因为错误看起来类似