I'm currently working on exporting an Angular 4 component library in the format described by the Angular Package Format. To simplify this, I generated a default setup using this Yeoman generator. Everything worked perfectly at first and I could generate a working library that I could import in another Angular application. I then updated our library files after fetching all the latest changes and tried to generate a new package. The build failed this time however, with an error that I couldn't link to one of the changes that I fetched.
The message:
[13:33:05] Starting 'ngc'...
TypeError: Cannot read property 'path' of undefined
at TsickleCompilerHost.getSourceMapKeyForSourceFile (C:\Projects\App\lib\node_modules\tsickle\build\src\tsickle_compiler_host.js:120:65)
at TsickleCompilerHost.downlevelDecorators (C:\Projects\App\lib\node_modules\tsickle\build\src\tsickle_compiler_host.js:202:52)
at TsickleCompilerHost.getSourceFile (C:\Projects\App\lib\node_modules\tsickle\build\src\tsickle_compiler_host.js:94:29)
at findSourceFile (C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:67909:29)
at processSourceFile (C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:67840:27)
at C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:67950:17
at Object.forEach (C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:1449:30)
at processReferencedFiles (C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:67948:16)
at findSourceFile (C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:67933:21)
at processImportedModules (C:\Projects\App\lib\node_modules\typescript\lib\typescript.js:68056:25)
Compilation failed
[13:33:13] 'ngc' errored after 7.52 s
Would someone be able to point out what can cause this error so that I have a clue what I should look for?
Turned out that a path in a // <reference path="some/path" />
comment was being replaced during the build which caused it to point to a non-existing file. That led to the TsickleCompilerHost
not finding a file, which in turn led to an undefined source file. Hence the TypeError: Cannot read property 'path' of undefined
message.