Window.XMLHttpRequest undefined

I created a node.js application for parsing angular2 HTML AST and Typescript AST for data extraction.

To do this, I need to import @angular/compiler and therefore @angular/core , which requires peerDependency zone.js@ ^0.6.21 .

The problem is that zone.js seems to be a bit broken with the node.js application at boot time:

 <my-project>/node_modules/zone.js/dist/zone.js:1286 var openNative = patchMethod(window.XMLHttpRequest.prototype, 'open', function () { return function (self, args) { ^ TypeError: Cannot read property 'prototype' of undefined at patchXHR (<my-project>/node_modules/zone.js/dist/zone.js:1286:55) at <my-project>/node_modules/zone.js/dist/zone.js:1253:1 at Zone.Zone.zoneSpec._properties (<my-project>/node_modules/zone.js/dist/zone.js:9:68) at Object.<anonymous> (<my-project>/node_modules/zone.js/dist/zone.js:12:2) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) 

Before I upgraded to angular2 final , I used angular 2.0.0-rc.1 and it requires zone.js@ ^0.6.6 , which works fine.

Already tried

  • Removing zone.js but not possible because it breaks the code.
  • Upgrading to zone.js@0.6.25 , all the same exact error.
+5
source share
1 answer

Make sure you import zone-node not zone :

 import 'zone.js/dist/zone-node'; 
0
source

Source: https://habr.com/ru/post/1258124/


All Articles