Angular2:使用ngc而不是tsc,获取TypeError:无法读取未定义的属性“text”

时间:2016-12-31 17:55:21

标签: angular

当前行为

使用我的lib运行tsc工作正常,但我正在尝试转移到ngc,因为我知道它可以做更好的转移工作。

错误是:

root@DESKTOP-VEUHFOL /cygdrive/c/msweb/ng-mslib
$ ./node_modules/.bin/ngc -p ./tsconfig.json
TypeError: Cannot read property 'text' of undefined
    at NodeObject.getText (C:\msweb\ng-mslib\node_modules\typescript\lib\typescript.js:78080:30)
    at Evaluator.evaluateNode (C:\msweb\ng-mslib\node_modules\@angular\compiler-cli\node_modules\@angular\tsc-wrapped\src\evaluator.js:512:66)
    at _loop_1 (C:\msweb\ng-mslib\node_modules\@angular\compiler-cli\node_modules\@angular\tsc-wrapped\src\collector.js:351:54)
    at C:\msweb\ng-mslib\node_modules\@angular\compiler-cli\node_modules\@angular\tsc-wrapped\src\collector.js:410:25
    at visitEachNode (C:\msweb\ng-mslib\node_modules\typescript\lib\typescript.js:13907:30)
    at Object.forEachChild (C:\msweb\ng-mslib\node_modules\typescript\lib\typescript.js:14078:24)
    at MetadataCollector.getMetadata (C:\msweb\ng-mslib\node_modules\@angular\compiler-cli\node_modules\@angular\tsc-wrapped\src\collector.js:233:12)
    at MetadataWriterHost.writeMetadata (C:\msweb\ng-mslib\node_modules\@angular\compiler-cli\node_modules\@angular\tsc-wrapped\src\compiler_host.js:151:51)
    at MetadataWriterHost.writeFile (C:\msweb\ng-mslib\node_modules\@angular\compiler-cli\node_modules\@angular\tsc-wrapped\src\compiler_host.js:143:19)
    at Object.writeFile (C:\msweb\ng-mslib\node_modules\typescript\lib\typescript.js:62522:132)
Compilation failed

但tsc

再次没有问题

tsconfig是:

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "lib": ["es2015", "dom"],
    "mapRoot": "./",
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "dist",
    "sourceMap": true,
    "target": "es5",
    "skipLibCheck": true,
    "paths": {
      "@angular/core": ["node_modules/@angular/core"],
      "rxjs/*": ["node_modules/rxjs/*"]
    },
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "angularCompilerOptions": {
    "strictMetadataEmit": true
  }
}

预期行为 如果tsc确实

,我希望ngc通过

使用说明书轻微复制问题 这是项目: https://github.com/born2net/ng-mslib 你可以运行tsc和ngc来看看diff

Windows 10 x64最新版本2.1和ng 2.4.1 节点:v6.5.0

问候

肖恩

1 个答案:

答案 0 :(得分:0)

问题是需要tsc 2.0.10 使用旧的打字稿修复它,直到ngc支持2.1