【问题标题】:Unhandled Promise rejection: xhr2.XMLHttpRequest is not a constructor未处理的 Promise 拒绝:xhr2.XMLHttpRequest 不是构造函数
【发布时间】:2018-04-01 04:25:40
【问题描述】:

我正在使用 Webpack 构建 ASPNetCore + Angular 5 应用程序。升级到 Angular5 后出现错误

Unhandled Promise rejection: xhr2.XMLHttpRequest is not a constructor ; Zone: <root> ; Task: Promise.then ; Value: TypeError: xhr2.XMLHttpRequest is not a constructor

这是什么意思? (如果您需要更广泛地打开问题,请告诉我要显示哪些文件) 我应用了最后一堆错误

 at ServerXhr.build (main-client.js:144947)
at Observable._subscribe (main-client.js:46829)
at Observable._trySubscribe (vendor.js:242)
at Observable.subscribe (vendor.js:230)
at scheduleTask (main-client.js:145000)
at Observable._subscribe (main-client.js:145038)
at Observable._trySubscribe (vendor.js:242)
at Observable.subscribe (vendor.js:230)
at Object.subscribeToResult (vendor.js:35030)
at MergeMapSubscriber._innerSub (vendor.js:64055) TypeError: xhr2.XMLHttpRequest is not a constructor

【问题讨论】:

  • 这个问题甚至没有提到错误是发生在服务器端还是客户端。 npmjs.com/package/xhr2在服务端渲染中被Http使用。

标签: angular promise xmlhttprequest


【解决方案1】:

您很可能已经解决了这个问题。但是,我刚刚遇到了这个问题,当我尝试设置 Angular Universal 时,我安装了 @angular/platform-server 包,但最终退出了。使用平台服务器运行系统会将 XHR2 注入系统的客户端。删除导入解决了我的问题。

【讨论】:

  • 非常感谢,为我节省了很多时间.. :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
  • 2018-03-19
  • 1970-01-01
  • 2018-12-09
  • 2021-10-14
相关资源
最近更新 更多