-
Notifications
You must be signed in to change notification settings - Fork 3k
Library socket.io-client is not compatible with latest Angular 6 #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There are indeed a number of I'm not sure about the side-effects of removing these references though. |
@darrachequesne Would it be possible to have these changes added to a fork of the project until properly resolved? |
@jessycormier what do you mean by "a fork of the project"? A first side-effect, it seems removing the global in darrachequesne/has-binary#4 breaks some Electron apps: darrachequesne/has-binary#5... |
Hi. Is here any progress? Any solution? Any recommended workaround? |
@realshaft - the above work-around worked for me in Ionic 4 / Angular 6 web app
|
@realshaft thank you , it works in angular6 ;) |
hello @everyone, import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject'; import * as io from 'socket.io-client'; @Injectable({ providedIn: 'root' }) export class SocketService { private url = 'http://localhost:3000'; private socket = io(this.url); // send a message to socket message( msg ) { // send msg this.socket.emit('chat', msg); } chat(msg) { this.socket$.emit('chat', msg); // let observable } } and the component file import { Component, OnInit } from '@angular/core'; import { SocketService } from '../../socket.service'; @Component({ selector: 'app-socket', templateUrl: './socket.component.html', styleUrls: ['./socket.component.scss'] }) export class SocketComponent implements OnInit { constructor( private socket: SocketService ) { } ngOnInit() { } send() { const msg = 'hello'; this.socket.message(msg); } } here is my socket server connection. i used MVC const gameModel = require('../models/game') const userModel = require('../models/users') const wsModel = require('../models/socket') const socket = require('socket.io') module.exports = (server) => { const io = socket(server); // WebSocket handler io.on('connection', (socket) => { console.log('a user connnected') }) // get the chat msg io.on('chat', (msg) => { // io.emit('res', json.stringify(msg)) console.log(msg); }) } thank you in advance |
here a bit hacky way to get it working: Inside the
Inside
Now you can use call
|
mine started working by simply adding the following
angular 6.1.0 This continues to work after upgrading to angular 7.1.x |
it help me, but why? |
It worked for me on Angular 7.x also, thanks. |
|
same solution works with angular 8 |
God Can't believe I say this. Same solution @mjarkk provided. Works in angular10! -- For me, the reason is that 2.x server doesn't work with 3.x client! |
After 3 versions this hack stil works lmao, i bet it works the same in angular 11. |
For future readers: this issue was fixed in Related commits:
Besides: an example with Angular 11 was added here: https://github.com/socketio/socket.io/tree/master/examples/angular-todomvc Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
I want to:
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:
angular/angular-cli#9827 (comment)
If you want to see this error for yourself, add to angular 6.0 app simple service like that below:
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
The text was updated successfully, but these errors were encountered: