Regression wrong error message during tests if runtime error occurs after constructor
Bug Report or Feature Request (mark with an x)
- [ x ] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.2.2 node: 6.11.0 os: win32 x64 @angular/animations: 4.3.3 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.2.2 @angular/compiler-cli: 4.3.3 @angular/language-service: 4.3.3
Repro steps.
- Create new project with @angular/cli version 1.2.2 or newer
- Modify src/app/app.component.ts, add OnInit interface and add any runtime error to ngOnInit
- run
ng test
Simple runtime error example:
...
export class AppComponent implements OnInit {
title = 'app';
example: string;
ngOnInit() {
console.log(this.example.length);
}
}
The log given by the failure.
Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'ng:///DynamicTestModule/AppComponent_Host.ngfactory.js'.
at http://localhost:9876/_karma_webpack_/polyfills.bundle.js:5182:35
at XMLHttpRequest.proto.(anonymous function) [as send] (http://localhost:9876/_karma_webpack_/polyfills.bundle.js:3767:20)
at Array.<anonymous> (node_modules/source-map-support/browser-source-map-support.js:107:176)
at node_modules/source-map-support/browser-source-map-support.js:101:106
at Array.<anonymous> (node_modules/source-map-support/browser-source-map-support.js:107:474)
at node_modules/source-map-support/browser-source-map-support.js:101:106
at a (node_modules/source-map-support/browser-source-map-support.js:101:312)
at b (node_modules/source-map-support/browser-source-map-support.js:104:348)
at node_modules/source-map-support/browser-source-map-support.js:105:245
at Array.map (native)
Desired functionality.
Display the actual error message with details about the error. Here's the output from 1.2.1.
@angular/cli: 1.2.1 node: 6.11.0 os: win32 x64 @angular/animations: 4.3.3 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.2.1 @angular/compiler-cli: 4.3.3 @angular/language-service: 4.3.3
Failed: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at AppComponent.webpackJsonp.../../../../../src/app/app.component.ts.AppComponent.ngOnInit (http://localhost:9876/_karma_webpack_/main.bundle.js:120:33)
at checkAndUpdateDirectiveInline (http://localhost:9876/_karma_webpack_/vendor.bundle.js:47071:19)
at checkAndUpdateNodeInline (http://localhost:9876/_karma_webpack_/vendor.bundle.js:48567:17)
at checkAndUpdateNode (http://localhost:9876/_karma_webpack_/vendor.bundle.js:48506:16)
at debugCheckAndUpdateNode (http://localhost:9876/_karma_webpack_/vendor.bundle.js:49367:59)
at debugCheckDirectivesFn (http://localhost:9876/_karma_webpack_/vendor.bundle.js:49308:13)
at Object.eval [as updateDirectives] (ng:///DynamicTestModule/AppComponent_Host.ngfactory.js:8:5)
at Object.debugUpdateDirectives [as updateDirectives] (http://localhost:9876/_karma_webpack_/vendor.bundle.js:49293:21)
at checkAndUpdateView (http://localhost:9876/_karma_webpack_/vendor.bundle.js:48473:14)
at callWithDebugContext (http://localhost:9876/_karma_webpack_/vendor.bundle.js:49693:42)
Mention any other details that might be useful.
This error is still occurring in 1.3.0-rc.5, the regression was added in 1.2.2, https://github.com/angular/angular-cli/commit/19f04af0777391cc72d096a0e315fe87bab161c6.
If a runtime errors occur during the constructor then the proper error displays, but sourcemaps still fail to show line in TypeScript.
It would be best if the actual error and line in typescript could be referenced.
the ng:/// prefix in source-map is added by : https://github.com/angular/angular/blob/master/packages/compiler/src/compile_metadata.ts#L683 and then loaded by the CLI via source-map-loader.
So, I think we can convert all sourcemaps to base64 sourceMapUrl for testing.
Experiencing this issue when running an Angular app within a JavaFX Webview, as opposed to unit tests. Building with sourcemaps=false fixes the issue. JavaFx under the hood this is just plain WebKit.
Specific user agent: Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/604.1 (KHTML, like Gecko) JavaFX/9 Safari/604.1
It would be interesting to know if anyone gets this when running with something like PhantomJS.
@limpygnome we definitely had the problem when running our unit tests with PhantomJS. But I think this also happened when running them with Chrome (with the then current version, i.e. something around version 60) so maybe not restricted to WebKit based browsers (if I remember correctly we also had this when running the tests through Firefox).
Is it recommended now to always turn off sourcemaps when running tests using ng test -sm=false?
Hi all, if angular 2+ project has ejected, need: in karma.conf.js in angularCli: {.. add sourcemaps: false, for eample: angularCli: { environment: 'dev', sourcemaps: false },
I think with Angular CLI 1.5 the problem has at least gotten better. Maybe it is even resolved completely?
@UrsMetz I'm using Angular Cli 1.5.4 here and nothing has gotten better. This is pretty annoying.
I'm experiencing this issue with CLI 1.6.3. Using --sourcemaps=false does not help at all.
For me it's failing during import ngrx StoreModule.forRoot([reducers]) to test. Solution: spyOn(StoreModule, 'forRoot').and.returnValue(Promise.resolve(true));
Experiencing this issue with CLI 1.6.1
1.6.6. - the error is still there, unfortunately. Disabling sourcemaps give some degree of clarity, but it's clearly just a workaround. Anyone has some ideas or guidelines on how not to get this error?
Seeing the issue with angular cli 1.6.5 on ubuntu with Chrome 64.0.3282.140
I am using angular cli v 1.6.5. In my case ng test --sourcemap=false is not returning any error but ng test is giving the error similar to mentioned in original issue.
As I need to generate Istanbul code coverage report, which requires sourcemap for typescript files to generate it properly, I tried to run tests using Firefox instead of Chrome and it worked well.
I'm experiencing this issue - wasted a good 2-3 hours until I found this.
Any plans to fix?
I'm facing the same issue, but with an ejected project.
How to --sourcemap=false when running tests with karma start ?
I wrote in post before: in karma.conf.js angularCli: { environment: 'dev', sourcemaps: false },
@asmolientsev thanks, missed that.
Still reproduces on Angular CLI 1.7.3. --sourcemap=false flag resolves this issue
I saw an "Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'ng:///DynamicTestModule/..too when writing a new component test.
In my case the reason was a poorly written template with *ngIf="queryTable.data". Revising this to *ngIf="queryTable && queryTable.data" solved the problem for me.
I think this confirms the observation from @Toxicable https://github.com/angular/angular-cli/issues/7296#issuecomment-347359285
@cf33 as a note, you can should use the angular operator. *ngIf="query Table?.data"