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-cliIs this a regression?
NoDescription
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:
- Created 3 years ago
- Comments:24 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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) {
)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.