question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'ngModule' of undefined

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

i am not sure.

Description

A clear and concise description of the problem...

when i run ng test, the some unit case fail for this reason:

TypeError: Cannot read property 'ngModule' of undefined

TypeError: Cannot read property 'ngModule' of undefined
    at isModuleWithProviders (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26229:18)
    at map (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26223:9)
    at <Jasmine>
    at Function.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:25879:26)
    at getNgModuleDef (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:1853:29)
    at isNgModule (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26232:14)
    at forEach (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26174:14)
    at <Jasmine>
    at transitiveScopesFor (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26172:32)
    at forEach (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26179:31)
    at <Jasmine>
    at transitiveScopesFor (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26172:32)
    at forEach (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26179:31)
    at <Jasmine>
    at transitiveScopesFor (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26172:32)

πŸ”¬ Minimal Reproduction

https://stackblitz.com/...

this is the private code. so i can not show the all code. I can only share the simplest case. ts code

import { ChangeDetectionStrategy, Component, Input } from '@angular/core';

@Component({
	selector: 'slate-initials-user-icon',
	templateUrl: './initials-user-icon.component.html',
	styleUrls: ['./initials-user-icon.component.scss'],
	changeDetection: ChangeDetectionStrategy.OnPush
})
export class InitialsUserIconComponent {
	@Input()
	public initials;
}

html

<p>
  {{ initials }}
</p>

test code

import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { InitialsUserIconComponent } from './initials-user-icon.component';

describe('InitialsUserIconComponent', () => {
	let component: InitialsUserIconComponent;
	let fixture: ComponentFixture<InitialsUserIconComponent>;

	beforeEach(
		waitForAsync(() => {
			TestBed.configureTestingModule({
				declarations: [InitialsUserIconComponent]
			}).compileComponents();
		})
	);

	beforeEach(() => {
		fixture = TestBed.createComponent(InitialsUserIconComponent);
		component = fixture.componentInstance;
		fixture.detectChanges();
	});

	it('should create', () => {
		expect(component).toBeTruthy();
	});
});

πŸ”₯ Exception or Error




TypeError: Cannot read property 'ngModule' of undefined
    at isModuleWithProviders (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26229:18)
    at map (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26223:9)
    at <Jasmine>
    at Function.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:25879:26)
    at getNgModuleDef (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:1853:29)
    at isNgModule (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26232:14)
    at forEach (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26174:14)
    at <Jasmine>
    at transitiveScopesFor (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26172:32)
    at forEach (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26179:31)
    at <Jasmine>
    at transitiveScopesFor (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26172:32)
    at forEach (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26179:31)
    at <Jasmine>
    at transitiveScopesFor (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26172:32)

🌍 Your Environment

Angular Version:




Angular CLI: 10.2.0
Node: 12.16.2
OS: darwin x64

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

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1002.0
@angular-devkit/build-angular      0.1002.0
@angular-devkit/core               10.2.0
@angular-devkit/schematics         10.2.0
@angular/cdk                       10.2.7
@angular/cli                       10.2.0
@angular/fire                      6.0.4
@angular/flex-layout               10.0.0-beta.32
@angular/material                  10.2.7
@angular/material-moment-adapter   10.2.7
@schematics/angular                10.2.0
@schematics/update                 0.1002.0
rxjs                               6.6.3
typescript                         3.9.7

Anything else relevant?

Chrome version: Version 86.0.4240.183 (Official Build) (x86_64)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
damingerdaicommented, Nov 5, 2020

it looks like the circular dependency issue. when i fixed the circular dependency issue, this error has not exist. so i have an another question: how to throw error instead of circular dependency warning when building?

1reaction
JoostKcommented, Nov 5, 2020

In this case the circular dep must have occurred in user code, as the compiler refrains from introducing new cycles. So I don’t think that #38211 is relevant here.

I believe it’s not possible to error for circular deps; they aren’t always a problem. It may be possible for the runtime JIT logic to detect an undefined NgModule import and produce a more helpful error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'ngModule' of undefined - Stack Overflow
The error occurs when the value is undefined, so we can put here a conditional breakpoint with the condition !value , what will...
Read more >
How to fix "Cannot read properties of undefined (reading ...
Jeffry Houser's Blog: How to fix "Cannot read properties of undefined (reading 'TRIDENT')" in an Angular Unit Test.
Read more >
cannot read properties of undefined ngmodel - You.com
I am trying to pass an object to NgModel in my angular template but I am recieving the error "ERROR TypeError: Cannot read...
Read more >
Angular Modules and NgModule - Complete Guide
Unhandled Promise rejection: Component Home is not part of any NgModule or the module has not been imported into your module. This ensures...
Read more >
uncaught typeerror cannot read property module of null
Uncaught TypeError: Cannot read property 'innerHTML' of null All this means is that you are trying to access a property of an object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found