Library socket.io-client is not compatible with latest Angular 6
See original GitHub issueI want to:
- report a bug - solved, look last two lines for workaround
Library socket.io-client is not compatible with latest Angular 6. There is error at execution time:
ReferenceError: global is not defined at Object…/node_modules/socket.io-client/node_modules/socket.io-parser/is-buffer.js (is-buffer.js:4)
Please read comment below to know more: https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814
If you want to see this error for yourself, add to angular 6.0 app simple service like that below:
import { Injectable } from 'angular/core';
import * as socketIo from 'socket.io-client';
@Injectable()
export class SocketService {
private socket;
constructor() {}
public initSocket(): void {
this.socket = socketIo();
}
}
Error disappears when you remove initSocket function.
Ok, there is workaround in Angular 6 to work with socket.io-client. Add (window as any).global = window; to polyfills.ts
Issue Analytics
- State:
- Created 5 years ago
- Reactions:43
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Client Installation | Socket.IO
The Socket.IO client is compatible with bundlers like webpack or browserify. NPM; Yarn; pnpm. npm install socket.io-client
Read more >Angular 6 and Socket.IO - Socket.On not working
I'm trying to use socket.io with an Angular 6 project and it doesn't seem to be working. Here is my issue: I have...
Read more >socket.io-client - npm
Realtime application framework client. Latest version: 4.5.4, last published: a month ago. Start using socket.io-client in your project by ...
Read more >How To Create a Real-Time App with Socket.IO, Angular, and ...
Step 1 — Setting Up the Project Directory and Creating the Socket Server · Step 2 — Installing @angular/cli and Creating the Client...
Read more >How to Integrate Socket.IO with Angular 2021 - Ultimate Akash
npm install -g @angular/cli · ng new client //client is project name · cd client npm i ngx-socket-io · import { NgModule }...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
mine started working by simply adding the following
angular 6.1.0 socket.io-client 2.1.1
This continues to work after upgrading to angular 7.1.x
@realshaft - the above work-around worked for me in Ionic 4 / Angular 6 web app