angular / angular

Deliver web apps with confidence 🚀
https://angular.dev
MIT License
95.57k stars 25.13k forks source link

Null pointer exception in template parser #19906

Closed crisbeto closed 6 years ago

crisbeto commented 6 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

The compiler throws a null pointer error that points to this line.

Full stack trace:

Error: TypeError: Cannot read property 'type' of null
    at C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:25385:26
    at Array.forEach (native)
    at removeSummaryDuplicates (C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:25384:11)
    at TemplateParser.tryParseHtml (C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:24393:51)
    at TemplateParser.tryParse (C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:24370:21)
    at TemplateParser.parse (C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:24332:44)
    at AotCompiler._parseTemplate (C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:29710:60)
    at AotCompiler._compileComponent (C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:29682:23)
    at C:\projects\material2\node_modules\@angular\compiler\bundles\compiler.umd.js:29528:55
    at Array.forEach (native)

Minimal reproduction of the problem with instructions

  1. Check out https://github.com/crisbeto/material2/tree/ng-5
  2. npm install
  3. npm run demo-app.

Environment


Angular version: 5.0.0-rc.4

For Tooling issues:
- Node version: 8.2.1
- Platform:  Windows

cc @chuckjaz

chuckjaz commented 6 years ago

This is two problems that we are approaching independently.

1) There is an error during template validation that is being reported because the the configuration of the the project is unexpected. We are now validating templates and the we are not able to find some of the metadata during emit.

2) The error reporting is getting lost and resulting in the violation of an internal constraint (that is, the decorator array should never contain a null).

We are addressing (1) by tying template validation to fullTemplateTypeCheck which is false by default. Invoking ngc for libraries will revert to the 4.0.0 behavior (just generating metadata instead of trying to validate it). The templates will now only be validated when fullTemplateTypeCheck is enabled. @tbosch is working on this.

(2) is being addressed by reverting part of the change made to fix getLazyRoutes for JIT programs. We switched to an error collection model (used by the language service) instead of an exception reporting model. We are switching back to exceptions for ngc but will continue to use error collection for getLazyRoutes and the language service. @chuckj is working on this.

We should support the configuration of projects that material is using and will address that post 5.0.0.

tbosch commented 6 years ago

Regarding (1): See https://github.com/angular/angular/pull/19909

tbosch commented 6 years ago

Closing as the corresponding PRs have landed on master.

cormacrelf commented 6 years ago

This is happening again with Ng-packagr v4, which has enabled both skipTemplateCodegen and fullTemplateTypeCheck, but relevantly to v4, also enableResourceInlining. Is that an inherently bad combination or a bug?

Reopen or new issue? @chuckjaz

Tsconfig: https://github.com/dherges/ng-packagr/blob/master/src/lib/ts/conf/tsconfig.ngc.json

Repro:

cormacrelf commented 6 years ago

Also I didn’t mean to unassign @chuckjaz, maybe that’s a GitHub syntax thing. I’m not actually allowed to unassign people AFAIK, being a random user.

dherges commented 5 years ago

In TemplateParser#tryParseHtml the values of htmlAstWithErrors.errors contain null values. That's all I found out so far.

Angular CLI: 6.2.2
Node: 10.10.0
OS: linux x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.8.2
@angular-devkit/schematics        0.8.2
@angular/cdk                      6.4.7
@angular/cli                      6.2.2
@ngtools/json-schema              1.1.0
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.1
@schematics/update                0.8.2
ng-packagr                        4.1.1
rxjs                              6.3.2
typescript                        2.9.2
webpack                           4.8.3
dherges commented 5 years ago

After trying and trying, my workaround is to set fullTemplateTypeCheck: false ... i opened an issue on ng-packagr ng-packagr/ng-packagr#1087

angular-automatic-lock-bot[bot] commented 4 years ago

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.