question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

🐞 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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jar240commented, Nov 7, 2020

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

2reactions
jar240commented, Oct 22, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular: Moving a library into a directory causes issues
Note: The path being used is incorrect. It should be 'C:/Users/user/projectName/projects/libs/libraryName/librarytsconfig.json' instead of ...
Read more >
Documentation - tsc CLI Options - TypeScript
Flag Type Default ‑‑allowJs boolean false ‑‑allowUmdGlobalAccess boolean false ‑‑allowUnreachableCode boolean
Read more >
@rollup/plugin-typescript - npm
Some of Typescript's CompilerOptions affect how Rollup builds files. noEmitOnError. Type: Boolean Default: false. If a type error is detected,Β ...
Read more >
The mypy configuration file - mypy 0.991 documentation
py file and not part of the files, modules and packages provided on the command line. The four possible values are normal ,...
Read more >
How To Update Angular CLI To Latest Version
If you get any error try manual installation. npm i rxjs-compat npm i @angular-devkit/build-angular. And Angular CLI 6 no longer uses intlΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found