Repository: angular
Issue: Uninformative error message with `ngForTrackBy` - `Error: Could not resolve [object Object] / undefined`
Labels: hotlist: error messages,state: has PR,area: compiler,P4,compiler: template type-checking

### Command

build, serve

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

Hi there! I hope I am at the right place for this issue; if not please let me know! 😃

When using `[ngForTrackBy]` together with the `*ngFor` structural directive (I know (now) that this is wrong 😄), the compilation of an Angular 15 app crashes with an ambiguous error message

```console
$ ng build
✔ Browser application bundle generation complete.

./src/main.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Could not resolve [object Object] / undefined
```

Also, the stack trace given by `ng build --verbose` does not give any hint on the origin of the issue:

```
ModuleBuildError: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Could not resolve [object Object] / undefined
    at /Users/user/dev/trackby-repro/node_modules/@ngtools/webpack/src/ivy/loader.js:81:18
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at processResult (/Users/user/dev/trackby-repro/node_modules/webpack/lib/NormalModule.js:760:19)
    at /Users/user/dev/trackby-repro/node_modules/webpack/lib/NormalModule.js:862:5
    at /Users/user/dev/trackby-repro/node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /Users/user/dev/trackby-repro/node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at context.callback (/Users/user/dev/trackby-repro/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /Users/user/dev/trackby-repro/node_modules/@ngtools/webpack/src/ivy/loader.js:81:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```


### Minimal Reproduction

```ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div *ngFor="let c of cs" [ngForTrackBy]="trackByFn(c)">
      {{c.id}} - {{c.name}}
    </div>`,
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  cs = [
    {id: 123, name: "Test"},
    {id: 124, name: "Test"},
  ]

  trackByFn(cs: {id: number, name: string}) {
    return cs.id
  }
}
```

### Exception or Error

```text
./src/main.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Could not resolve [object Object] / undefined
```


### Your Environment

```text
_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 15.0.5
Node: 18.14.2
Package Manager: npm 9.5.0
OS: darwin arm64

Angular: 15.2.7
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1502.6
@angular-devkit/build-angular   15.2.6
@angular-devkit/core            15.2.6
@angular-devkit/schematics      15.0.5
@angular/cli                    15.0.5
@schematics/angular             15.0.5
rxjs                            7.5.7
typescript                      4.8.4
```


### Anything else relevant?

_No response_