Skip to content

Uninformative error message with ngForTrackBy - Error: Could not resolve [object Object] / undefined #49931

Closed as not planned

Description

@fgdroege

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

$ 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

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

./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

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


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

Activity

  1. changed the title [-]Uninformative error message with ngForTrackBy: ./src/main.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): Error: Could not resolve [object Object] / undefined[/-] [+]Uninformative error message with ngForTrackBy Error: Could not resolve [object Object] / undefined[/+] on Apr 19, 2023
  2. added
    area: compiler
    on Apr 19, 2023
  3. added this to the needsTriage milestone on Apr 19, 2023
  4. changed the title [-]Uninformative error message with ngForTrackBy Error: Could not resolve [object Object] / undefined[/-] [+]Uninformative error message with `ngForTrackBy` - `Error: Could not resolve [object Object] / undefined`[/+] on Apr 19, 2023
  5. self-assigned this
    on Oct 29, 2023
  6. added
    P4
    on Oct 29, 2023
  7. modified the milestones: needsTriage, Backlog on Oct 29, 2023
  8. added a commit that references this issue on Oct 6, 2024
    ba9865b
  9. JeanMeche commented on Aug 29, 2025

    @JeanMeche
    Member

    We've deprecated the NgFor structural directive in favor of the @for block in v20. We likely won't be addressing this issue

  10. added a commit that references this issue on Sep 17, 2025
    1c89c45
  11. added 2 commits that reference this issue on Sep 17, 2025
    89cf62f
    8843707
  12. added a commit that references this issue on Sep 18, 2025
    e27792d
  13. angular-automatic-lock-bot commented on Sep 30, 2025

    @angular-automatic-lock-bot

    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.

  14. locked and limited conversation to collaborators on Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P4area: compilercompiler: template type-checkinghotlist: error messagesstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions