【发布时间】:2021-02-24 10:17:50
【问题描述】:
我想将socket.io-client (v3) 添加到我的 Angular 应用程序中。我使用 Bazel 来构建和运行 Angular。不幸的是,我在运行 ts_devserver 时在浏览器控制台中收到此错误:
ERROR Error: Uncaught (in promise): TypeError: XMLHttpRequest is not a constructor
TypeError: XMLHttpRequest is not a constructor
at ts_scripts.js?v=80175740:15476
at Object.14.../globalThis (ts_scripts.js?v=80175740:15480)
我在使用 Socket.IO v2 时遇到了同样的问题。 但是old solution 不再起作用了。
这一次,甚至没有在生产环境中运行 Angular 应用程序。
最小复制
你可以自己试试:flolu/angular-bazel-socketio3-issue
只需运行yarn install,然后运行yarn dev。错误出现在浏览器控制台中 http://localhost:4200。
请注意,在production 中使用yarn prod 在http://localhost:4000 运行应用程序时会出现另一个错误:
ERROR Error: Uncaught (in promise): ReferenceError: Cannot access 'e' before initialization
ReferenceError: Cannot access 'e' before initialization
at home.module-7db83ffb.js:formatted:953
【问题讨论】:
标签: angular typescript socket.io xmlhttprequest bazel