Search code examples
angularsocket.ioangular2-seed

Errors for socket.io in angular 2 seed


Unable to integrate socket.io in angular2-seed app. Actually my code is

private mySocket:any;    
getSocketValue() {
    console.log("this.mySocket"+this.mySocket)
    if(this.mySocket) {
      this.mySocket = io(Config.socket_url);
    }
    return this.mySocket;
}

When using that code I am getting an error like enter image description here


Solution

  • Socket.io-client not loaded properly
    

    Tried below, It worked npm install @types/socket.io-client --save define socket.io-client in tools/config/seed.config.ts

    i.e in SYSTEM_CONFIG_DEV->
    path: {
    ...,
    'socket.io-client' : `node_modules/socket.io-client/dist/socket.io`,// for latest versions of socket.io
    'socket.io-client' : `node_modules/socket.io-client/socket.io`,// for older versions of socket.io
    ...
    }
    

    add in SYSTEM_BUILDER_CONFIG for production mode

    path: {
        ...,
        'socket.io-client' : `node_modules/socket.io-client/dist/socket.io`,// for latest versions of socket.io
        'socket.io-client' : `node_modules/socket.io-client/socket.io`,// for older versions of socket.io
        ...
        }