Skip to content

Compile error related to nullish coalescing in template  #45413

@elnipa

Description

@elnipa

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

After updating one of my projects from v13.1.x to v.13.2.x or v13.3.x the project would not compile anymore with a very generic error message.
Narrowing down the bug was thus very difficult. By successive testing of all modules in the project I was able to achieve a minimal reproduction of the bug.

The following setup crashes the app:

  • nullish coalescing in template which might not be needed (The left side of this nullish coalescing operation does not include 'null' or 'undefined' in its type, therefore the '??' operator can be safely removed.)
  • strictTemplates mode in angular compiler options enabled
  • component using a generic extending a Record

Removing the unnecessary nullish coalescing in this case makes the project compile again.

Please provide a link to a minimal reproduction of the bug

https://github.com/elnipa/ng13.3-null-span-bug

Please provide the exception or error you saw

<e> [webpack-dev-middleware] Error: Cannot read properties of null (reading 'span')
<e>     at analyzingFileEmitter (C:\.....\node_modules\@ngtools\webpack\src\ivy\plugin.js:456:23)
<e>     at processTicksAndRejections (node:internal/process/task_queues:96:5)
<e>     at async AngularWebpackPlugin.rebuildRequiredFiles (C:\.....\node_modules\@ngtools\webpack\src\ivy\plugin.js:281:36)
<e>     at async C:\.....\node_modules\@ngtools\webpack\src\ivy\plugin.js:222:17

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.3.0
Node: 16.13.0
Package Manager: npm 8.1.0
OS: win32 x64

Angular: 13.3.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.0
@angular-devkit/build-angular   13.3.0
@angular-devkit/core            13.3.0
@angular-devkit/schematics      13.3.0
@schematics/angular             13.3.0
rxjs                            7.5.5
typescript                      4.6.2

Anything else?

No response

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilercompiler: template type-checkingstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions