angular: compiler-cli typecheck fails if filepath is wrong without useful log

🐞 bug report

Affected Package

The issue is caused by package @angular/compiler-cli

Is this a regression?

No

Description

The checker for file from the ngts/typecheck package (https://github.com/angular/angular/blob/master/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts#L119) does not throw a descriptive error, when the filename and class/interface name is not the same when using path aliases. It just throws generic error message

“ERROR in TypeError: Cannot read property ‘hasInlines’ of undefined”. 

After adding a few lines to error out the filepath I was able to pinpoint my error.

Wanted solution: the checker should print a descriptive error instead of a generic one.

The error only occurs, when the wrongly typed file is on an tsconfig path alias!

A proposed change is here https://github.com/angular/angular/commit/035c771dd87822777ef596eccbc50db2b3fa65fa

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-compiler-cli-path-alias-error?file=src/app/other/other.component.ts

🔥 Exception or Error

ERROR in TypeError: Cannot read property 'hasInlines' of undefined
    at TemplateTypeCheckerImpl.getDiagnosticsForFile (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\checke
r.js:107:28)
    at NgCompiler.getTemplateDiagnostics (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@angular\compiler-cli\src\ngtsc\core\src\compiler.js:487:106)
    at NgCompiler.getDiagnostics (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@angular\compiler-cli\src\ngtsc\core\src\compiler.js:141:97)
    at NgtscProgram.getNgSemanticDiagnostics (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@angular\compiler-cli\src\ngtsc\program.js:152:45)
    at checkDiagnostics (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@ngtools\webpack\src\diagnostics.js:47:27)
    at Object.gatherDiagnostics (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@ngtools\webpack\src\diagnostics.js:86:13)
    at AngularCompilerPlugin._emit (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:1081:54)
    at AngularCompilerPlugin._update (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:872:50)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async AngularCompilerPlugin._make (C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:749:13)




🌍 Your Environment

Angular Version:

10.0.6



C:\Users\hoefken\Documents\infoapp\InfoApp-Frontend>ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.0.6
Node: 12.10.0
OS: win32 x64

Angular: 10.0.10
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.6
@angular-devkit/build-angular     0.1000.6
@angular-devkit/build-optimizer   0.1000.6
@angular-devkit/build-webpack     0.1000.6
@angular-devkit/core              10.0.6
@angular-devkit/schematics        10.0.6
@angular/cdk                      10.1.3
@angular/cli                      10.0.6
@angular/flex-layout              10.0.0-beta.32
@angular/material                 10.1.3
@ngtools/webpack                  10.0.6
@schematics/angular               10.0.6
@schematics/update                0.1000.6
rxjs                              6.6.2
typescript                        3.9.7
webpack                           4.43.0

Anything else relevant?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (5 by maintainers)

Commits related to this issue

Most upvoted comments

need help please

Um… if you look at your screenshot, you can see the problematic file. Here’s your screenshot annotated for clarity Looks like the issue is with your file show-com.component.ts. Look at the class declaration – if it’s not exactly “ShowComComponent”, then this is likely the issue. (when you you the Angular cli to generate a skeleton component, it sets the filename correctly based on the classname you declare.

This should get you unstuck, but this bug for which this issue was opened remains.

image

I’m experiencing this error too (Windows). To reproduce, create a component with class name “ThisIsMyComponent” and name the file “thisIsMyComponent.ts”. In my case, this was the problem.

To troubleshoot it (as suggested in this thread’s predecessor by @JoostK ), I added this line of code

console.log('sfPath: ' + sfPath); console.log('fileRecord is (un)defined? ' + typeof fileRecord);

…above the offending line (if (fileRecord.hasInlines) {) image

to the file: .\node_modules@angular\compiler-cli\src\ngtsc\typecheck\src\checker.js

…this will output “fileRecord is object” for all the “good” files, and “fileRecord is undefined” for the offending file.