2016-08-15 85 views
2

我試圖編譯我的程序時使用ngc編譯器。過去我沒有使用過ngc,但是我在博客上追蹤了幾個例子,使它看起來相當簡單。我的代碼在瀏覽器中運行良好,打字稿編譯器編譯得很好,但是當我使用ngc時出現以下錯誤。使用Angular2的AoT ngc編譯器獲取TypeError與RC5

TypeError: Cannot read property 'kind' of undefined 
at maybeGetSimpleFunction (node_modules\@angular\tsc-wrapped\src\collector.js:28:41) 
at node_modules\@angular\tsc-wrapped\src\collector.js:227:41 
at visitEachNode (node_modules\typescript\lib\typescript.js:8154:30) 
at Object.forEachChild (node_modules\typescript\lib\typescript.js:8314:24) 
at MetadataCollector.getMetadata (node_modules\@angular\tsc-wrapped\src\collector.js:189:12) 
at ReflectorHost.getMetadataFor (node_modules\@angular\compiler-cli\src\reflector_host.js:217:43) 
at StaticReflector.getModuleMetadata (node_modules\@angular\compiler-cli\src\static_reflector.js:478:40) 
at CodeGenerator.readFileMetadata (node_modules\@angular\compiler-cli\src\codegen.js:33:51) 
at node_modules\@angular\compiler-cli\src\codegen.js:91:74 
at Array.map (native) 
Compilation failed 

任何幫助表示讚賞。

+0

你跑哪個ngc命令?你看到每個組件和模塊的NgFactory文件嗎?你能分享你的main.ts文件嗎? – Sanket

+0

ngc -p ./src其中src是我的htm,tsconfig和angular2應用程序所在的地方。所以基本上運行ngc與我用於tsc的選項相同。沒有生成工廠文件。 – wiredprogrammer

+0

我的打字稿和javascript文件並排居住。我錯誤地認爲ngc只關心打字稿文件? – wiredprogrammer

回答

1

這篇文章https://stackoverflow.com/a/39541250/2786847幫助我解決了同樣的問題。我不得不將export default function() {}更改爲export function myFunction() {}

+0

感謝您的回覆。幾周前我已經找到了這篇文章。我推薦這篇文章供讀者閱讀,以供任何人試圖讓他們的代碼對AoT編譯器的靜態分析友好。 https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.2p5ul5txt約翰帕帕已經表示,他會提出一個Gist的文章也推薦標準編碼以幫助AoT編譯。 – wiredprogrammer