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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ivy (aot) Could not resolve [object Object] / undefined at Scope.resolve #39744

Closed
jaffbeto opened this issue Nov 18, 2020 · 6 comments
Closed
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking P2 The issue is important to a large percentage of users, with a workaround state: confirmed state: has PR
Milestone

Comments

@jaffbeto
Copy link

🐞 bug report

Affected Package

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

Description

this its only in Angular 11.0.0

enable ivy
run ng build --aot
or "aot": true in angular.json

this same bug 30677

🔥 Exception or Error



Error: Error: Could not resolve [object Object] / undefined
    at Scope.resolve (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:1318:23)
    at TcbEventHandlerTranslator.TcbExpressionTranslator.resolveTarget (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:1877:35)
    at TcbEventHandlerTranslator.TcbExpressionTranslator.resolve (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:1786:29)
    at TcbEventHandlerTranslator.resolve (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:2034:45)
    at AstTranslator.maybeResolve (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:1771:84)
    at AstTranslator.translate (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:74:33)
    at Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:204:68
    at Array.map ()
    at AstTranslator.visitMethodCall (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:204:33)
    at MethodCall.visit (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler\bundles\compiler.umd.js:8218:28)
    at AstTranslator.translate (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:78:24)
    at Object.astToTypescript (Z:\GIT_LOCAL\tools\CloudTool\CloudWebTool\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:55:27)


🌍 Your Environment

Angular Version:



Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.1
@angular-devkit/build-angular   0.1100.1
@angular-devkit/core            11.0.1
@angular-devkit/schematics      11.0.1
@angular/cli                    11.0.1
@schematics/angular             11.0.1
@schematics/update              0.1100.1
rxjs                            6.6.3
typescript                      4.0.5


Anything else relevant?

@JoostK
Copy link
Member

JoostK commented Nov 18, 2020

@jaffbeto Heya, this looks like a bug but it's unclear what the cause is. Could you share a reproduction for us to investigate? Thanks!

@JoostK JoostK added area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Nov 18, 2020
@ngbot ngbot bot modified the milestone: Backlog Nov 18, 2020
@JoostK JoostK added the needs reproduction This issue needs a reproduction in order for the team to investigate further label Nov 18, 2020
@joebieb
Copy link

joebieb commented Nov 20, 2020

I was able to reproduce this error by accidently using a capital "F" in a form control...
<Form class="login-form" #f="ngForm" (ngSubmit)="onSubmit(f)">

once I changed it to...
<form class="login-form" #f="ngForm" (ngSubmit)="onSubmit(f)">
the error went away.

@AlonsoK28
Copy link

AlonsoK28 commented Nov 21, 2020

Same for me, after update from ng 9 to ng 11
I´ve tried to reinstall npm dependencies several times but still with this error

error log

Option "extractCss" is deprecated: Deprecated since version 11.0. No longer required to disable CSS extraction for HMR.
✔ Browser application bundle generation complete.

Error: Error: Could not resolve [object Object] / undefined
    at Scope.resolve (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1318:23)
    at Scope.resolve (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1315:36)
    at TcbExpressionTranslator.resolveTarget (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1877:35)
    at TcbExpressionTranslator.resolve (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1786:29)
    at AstTranslator.maybeResolve (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1771:84)
    at AstTranslator.translate (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/expression.js:74:33)
    at AstTranslator.visitPropertyRead (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/expression.js:227:66)
    at PropertyRead.visit (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler/bundles/compiler.umd.js:8168:28)
    at AstTranslator.translate (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/expression.js:78:24)
    at Object.astToTypescript (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/expression.js:55:27)
    at TcbExpressionTranslator.translate (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1771:33)
    at tcbExpression (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1759:27)
    at TcbUnclaimedInputsOp.execute (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:848:32)
    at Scope.executeOp (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1428:26)
    at Scope.render (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:1335:22)
    at TcbTemplateBodyOp.execute (/Users/user/Documents/dev/myproject/node_modules/@angular/compiler-cli/src/ngtsc/typecheck/src/type_check_block.js:318:40)

node v12.18.2

angular cli

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

Angular CLI: 11.0.2
Node: 12.18.2
OS: darwin x64

Angular: 11.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1100.2 (cli-only)
@angular-devkit/build-angular      0.1100.2
@angular-devkit/core               11.0.2 (cli-only)
@angular-devkit/schematics         11.0.2
@angular/cdk                       11.0.0
@angular/flex-layout               9.0.0-beta.29
@angular/material                  11.0.0
@angular/material-moment-adapter   9.0.0
@schematics/angular                11.0.2
@schematics/update                 0.1100.2
ng-packagr                         11.0.2
rxjs                               6.6.3
typescript                         4.0.5

package.json

{
  "name": "myproject",
  "version": "1.0.0",
  "scripts": {
    "postinstall": "ngcc",
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "qa": "ng b --prod --c=qa",
    "prod": "ng b --prod"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.1.0",
    "@angular-material-extensions/google-maps-autocomplete": "^4.1.1",
    "@angular/animations": "~11.0.2",
    "@angular/cdk": "^11.0.0",
    "@angular/common": "^11.0.2",
    "@angular/compiler": "^11.0.2",
    "@angular/core": "^11.0.2",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "^11.0.2",
    "@angular/material": "^11.0.0",
    "@angular/material-moment-adapter": "^9.0.0",
    "@angular/platform-browser": "^11.0.2",
    "@angular/platform-browser-dynamic": "~11.0.2",
    "@angular/router": "~11.0.2",
    "@angular/service-worker": "~11.0.2",
    "@types/googlemaps": "^3.39.2",
    "bootstrap": "^4.4.1",
    "date-fns": "^2.12.0",
    "moment": "^2.24.0",
    "ngx-bootstrap": "^5.3.2",
    "ngx-flash-messages": "^1.0.4",
    "ngx-mask": "^8.0.3",
    "ngx-pagination": "^5.0.0",
    "ngx-scrolltop": "^0.8.1",
    "ngx-toastr": "^12.0.0",
    "rxjs": "~6.6.3",
    "rxjs-compat": "^6.5.4",
    "tslib": "^2.0.3",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1100.2",
    "@angular/cli": "^11.0.2",
    "@angular/compiler-cli": "~11.0.2",
    "@angular/language-service": "~11.0.2",
    "@types/googlemaps": "^3.39.2",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.2.2",
    "install": "^0.13.0",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.1.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "ng-packagr": "^11.0.2",
    "protractor": "~7.0.0",
    "skeleton-placeholder": "^1.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.3",
    "typescript": "^4.0.5"
  }
}

@JoostK JoostK added P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Nov 21, 2020
@JoostK
Copy link
Member

JoostK commented Nov 22, 2020

I was able to reproduce this error by accidently using a capital "F" in a form control...
<Form class="login-form" #f="ngForm" (ngSubmit)="onSubmit(f)">

once I changed it to...
<form class="login-form" #f="ngForm" (ngSubmit)="onSubmit(f)">
the error went away.

@joebieb Thank you, that has helped in finding the issue. It appears to have regressed in #38618, where referring a reference that is bound to an unknown directive now crashes. Before, it would have reported an error:

ERROR in src/app/app.component.html:1:10 - error NG8003: No directive found with exportAs 'test'.

1 <div #a="test"></div> {{ a() }}
           ~~~~

  src/app/app.component.ts:5:16
    5   templateUrl: './app.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component AppComponent.

I'm working on a fix.

@JoostK JoostK added state: confirmed and removed needs reproduction This issue needs a reproduction in order for the team to investigate further labels Nov 22, 2020
JoostK added a commit to JoostK/angular that referenced this issue Nov 22, 2020
…stead of crashing

If a template declares a reference to a missing target then referring to
that reference from elsewhere in the template would crash the template
type checker, due to a regression introduced in angular#38618. This commit
fixes the crash by ensuring that the invalid reference will resolve to
a variable of type any.

Fixes angular#39744
@georgemichalagas
Copy link

georgemichalagas commented Nov 22, 2020

The problem in my project, is inside this page. When i comment out all the code, is working. when i enable the code, i get this error.
below the code.
You can also find the code here: https://stackblitz.com/edit/mte-demo?file=src%2Fapp%2Fapp.component.ts

The HTML file:

<ng-container matColumnDef="position">
  <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.position}} </mat-cell>
</ng-container>

<ng-container matColumnDef="name">
  <mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.name}} </mat-cell>
</ng-container>

<ng-container matColumnDef="surname">
  <mat-header-cell *matHeaderCellDef> Surname </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.surname}} </mat-cell>
</ng-container>

<ng-container matColumnDef="birth">
  <mat-header-cell *matHeaderCellDef> Birth </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.birth}} </mat-cell>
</ng-container>

<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
Excel Csv Json Txt

The TS File:

import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { MatDialog, MatDialogRef, } from '@angular/material/dialog';
import { MatPaginator } from '@angular/material/paginator';
import { MatTableDataSource } from '@angular/material/table';

export interface Element {
name: string;
position: number;
surname: string;
birth: string;
}

const ELEMENT_DATA: Element[] = [
{position: 1, name: 'Albert', surname: 'Einstein', birth: '1879'},
{position: 2, name: 'Marie', surname: 'Curie', birth: '1867'},
{position: 3, name: 'Enrico', surname: 'Fermi', birth: '1901'},
{position: 4, name: 'Dmitri', surname: 'Mendeleev', birth: '1834'},
{position: 5, name: 'Alfred', surname: 'Nobel', birth: '1833'},
{position: 6, name: 'Ernest', surname: 'Lawrence', birth: '1901'},
{position: 7, name: 'Glenn', surname: 'Seaborg', birth: '1912'},
{position: 8, name: 'Niels', surname: 'Bohr', birth: '1885'},
{position: 9, name: 'Lise', surname: 'Meitner', birth: '1878'},
{position: 10, name: 'Wilhelm', surname: 'Röntgen', birth: '1845'},
{position: 11, name: 'Nicolaus', surname: 'Copernicus', birth: '1473'},
{position: 12, name: 'Georgy', surname: 'Flyorov', birth: '1913'},
{position: 13, name: 'Yuri', surname: 'Oganessian', birth: '1933'},
{position: 14, name: 'Johan', surname: 'Gadolin', birth: '1760'},
{position: 15, name: 'Pierre', surname: 'Curie', birth: '1859'},
];

@component({
selector: 'app-export-table',
templateUrl: './export-table.component.html',
styleUrls: ['./export-table.component.scss']
})

export class ExportTableComponent implements OnInit {
@input() dataRows: any[] = [];
@input() datacolumns: any[] = [];

constructor(public dialogRef: MatDialogRef,
public dialog: MatDialog) { }

title = 'mte-test';
displayedColumns = ['position', 'name', 'surname', 'birth'];
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
dataSource: MatTableDataSource<Element>;

ngOnInit(): void {
  this.dataSource = new MatTableDataSource<Element>(ELEMENT_DATA);
  this.dataSource.paginator = this.paginator;
}

}

AndrewKushnir pushed a commit that referenced this issue Nov 24, 2020
…stead of crashing (#39805)

If a template declares a reference to a missing target then referring to
that reference from elsewhere in the template would crash the template
type checker, due to a regression introduced in #38618. This commit
fixes the crash by ensuring that the invalid reference will resolve to
a variable of type any.

Fixes #39744

PR Close #39805
@angular-automatic-lock-bot
Copy link

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 Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking P2 The issue is important to a large percentage of users, with a workaround state: confirmed state: has PR
Projects
None yet
5 participants