ReferenceError:运行我的 angular 6 通用应用程序时未定义 XMLHttpRequest
我制作了一个依赖 Angularfire2 的 Angular 6 项目.我正在使用 firestore 和 firebase 存储.我已将我的应用程序转换为 angular 通用,当我运行 server.js
时,它说正在侦听 localhost:4000
但只要我用 localhost 打开浏览器:4200
终端显示如下错误:
I have made a Angular 6 project with dependency Angularfire2 .
I am using firestore and firebase storage.
I have converted my app to angular universal and when i run server.js
it says listening on localhost:4000
but as soon as i open the browser with localhost:4200
the terminal shows the following error:
ReferenceError: XMLHttpRequest is not defined
安装这些依赖项:
npm install --save-dev ws xmlhttprequest
然后将其添加到您的 server.ts
文件
Then add this to your server.ts
file
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
如果您在使用 Firebase 时遇到 SSR 的任何其他问题,检查这篇文章是否已经涵盖它.
If you run into any other issue with SSR by using Firebase, check if this article already covers it.
来源: