Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ivy template typechecking fails with "ERROR in TypeError: Cannot read property 'getStart' of undefined" #32538

Closed
mattlewis92 opened this issue Sep 7, 2019 · 4 comments

Comments

@mattlewis92
Copy link
Contributor

commented Sep 7, 2019

馃悶 bug report

Affected Package

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

Is this a regression?

Not sure, it might have worked in previous betas

Description

When I try and run ivy on my app it fails to run template typechecking.

馃敩 Minimal Reproduction

https://github.com/mattlewis92/angular-calendar/tree/try-ivy-v2

馃敟 Exception or Error


ERROR in TypeError: Cannot read property 'getStart' of undefined
    at makeTemplateDiagnostic (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/diagnostics.js:165:45)
    at Object.translateDiagnostic (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/diagnostics.js:114:16)
    at collectDiagnostics (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/context.js:202:60)
    at TypeCheckContext.calculateTemplateDiagnostics (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/context.js:220:21)
    at NgtscProgram.getTemplateDiagnostics (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@angular/compiler-cli/src/ngtsc/program.js:375:26)
    at NgtscProgram.getNgSemanticDiagnostics (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@angular/compiler-cli/src/ngtsc/program.js:168:78)
    at checkDiagnostics (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@ngtools/webpack/src/gather_diagnostics.js:38:27)
    at Object.gatherDiagnostics (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@ngtools/webpack/src/gather_diagnostics.js:77:13)
    at AngularCompilerPlugin._emit (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:1036:61)
    at AngularCompilerPlugin._update (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:806:50)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async AngularCompilerPlugin._make (/Users/mattlewis/Code/open-source/angular-calendar/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:703:13)

馃實 Your Environment

Angular Version:


Angular CLI: 9.0.0-next.3
Node: 12.6.0
OS: darwin x64
Angular: 9.0.0-next.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.900.0-next.3
@angular-devkit/build-angular      0.900.0-next.3
@angular-devkit/build-ng-packagr   0.900.0-next.3
@angular-devkit/build-optimizer    0.900.0-next.3
@angular-devkit/build-webpack      0.900.0-next.3
@angular-devkit/core               9.0.0-next.3
@angular-devkit/schematics         9.0.0-next.3
@angular/cdk                       8.1.3
@angular/cli                       9.0.0-next.3
@ngtools/webpack                   9.0.0-next.3
@schematics/angular                9.0.0-next.3
@schematics/update                 0.900.0-next.3
ng-packagr                         5.5.0
rxjs                               6.5.3
typescript                         3.5.3
webpack                            4.39.3

Anything else relevant?
Nope

@JoostK

This comment has been minimized.

Copy link
Member

commented Sep 7, 2019

So the issue here is that there's an incorrect assumption when the template source mapping info is derived for pre-analyzed templates. The code expects a pre-analyzed template to always originate from an external template, however this is not true: all templates are pre-analyzed as even inline templates can have stylesheets that have to be preloaded.

Looks like this case hasn't been caught in tests as there's no pre-analysis at all when ResourceLoader.canPreload is false. This is the case in the tests as it's dependent on having CompilerHost.readResource, which is only true in the CLI where a WebpackCompilerHost is used, whereas ngtsc's tests use a vanilla ts.CompilerHost.

JoostK added a commit to JoostK/angular that referenced this issue Sep 8, 2019
Prior to this change, the template source mapping details were always
built during the analysis phase, under the assumption that pre-analysed
templates would always correspond with external templates. This has
turned out to be a false assumption, as inline templates are also
pre-analyzed to be able to preload any stylesheets included in the
template.

This commit fixes the bug by capturing the template source mapping
details at the moment the template is parsed, which is either during the
preanalysis phase when preloading is available, or during the analysis
phase when preloading is not supported.

Tests have been added to exercise the template error mapping in
asynchronous compilations where preloading is enabled, similar to how
the CLI performs compilations.

Fixes angular#32538
@JoostK JoostK added the state: has PR label Sep 8, 2019
@vgb1993

This comment has been minimized.

Copy link

commented Sep 8, 2019

Hy I get the same error quite often. Any workaround to get ng s working for now?

_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / 鈻 \ | '_ \ / _ | | | | |/ ` | '__| | | | | | |
/ ___ | | | | (
| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/

Angular CLI: 9.0.0-next.3
Node: 12.4.0
OS: win32 x64
Angular: 9.0.0-next.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version

@angular-devkit/architect 0.900.0-next.3
@angular-devkit/build-angular 0.900.0-next.3
@angular-devkit/build-ng-packagr 0.900.0-next.3
@angular-devkit/build-optimizer 0.900.0-next.3
@angular-devkit/build-webpack 0.900.0-next.3
@angular-devkit/core 9.0.0-next.3
@angular-devkit/schematics 9.0.0-next.3
@angular/cli 9.0.0-next.3
@ngtools/webpack 9.0.0-next.3
@schematics/angular 9.0.0-next.3
@schematics/update 0.900.0-next.3
ng-packagr 5.5.0
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.3`

@mattlewis92

This comment has been minimized.

Copy link
Contributor Author

commented Sep 9, 2019

Nice one, thanks for the super quick turnaround @JoostK! 馃槃

@matsko matsko closed this in a64eded Sep 9, 2019
arnehoek added a commit to arnehoek/angular that referenced this issue Sep 26, 2019
鈥gular#32544)

Prior to this change, the template source mapping details were always
built during the analysis phase, under the assumption that pre-analysed
templates would always correspond with external templates. This has
turned out to be a false assumption, as inline templates are also
pre-analyzed to be able to preload any stylesheets included in the
template.

This commit fixes the bug by capturing the template source mapping
details at the moment the template is parsed, which is either during the
preanalysis phase when preloading is available, or during the analysis
phase when preloading is not supported.

Tests have been added to exercise the template error mapping in
asynchronous compilations where preloading is enabled, similar to how
the CLI performs compilations.

Fixes angular#32538

PR Close angular#32544
@angular-automatic-lock-bot

This comment has been minimized.

Copy link

commented Oct 10, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can鈥檛 perform that action at this time.