I want to add socket.io-client (v3) to my Angular application. I use Bazel to build and run Angular. Unfortunately I get this error in the browser console when running the 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)
I had the same issue when working with Socket.IO v2. But the old solution doesn't work anymore.
Also this time, not even running the Angular app in production works.
Minimal Reproduction
You can try it yourself: flolu/angular-bazel-socketio3-issue
Just run yarn install
and then yarn dev
. The error is in the browser console at http://localhost:4200.
And note that there is another error when running the app in production with yarn prod
at 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