1

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

praveen kumar
  • 1,474
  • 4
  • 13
  • 19

2 Answers2

1

Seems your socket io is not loaded.!

Include it in your systemJS configuration.

System.config({
    packages: {
        ...
        "socket.io-client": {"defaultExtension": "js"}
    },
    map: {
        "socket.io-client": "node_modules/socket.io-client/socket.io.js"
    }
});

And if u generated typings for it then,

{
  "ambientDependencies": {
    ...
    "socket-io-client":"github:DefinitelyTyped/DefinitelyTyped/socket.io-client/socket.io-client.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
  }
}
Parth Ghiya
  • 6,929
  • 2
  • 30
  • 37
  • which seed file you are using ? You have to do something like this https://github.com/mgechev/angular-seed/wiki/Add-external-dependency – Parth Ghiya Feb 28 '17 at 06:48
  • It didn't worked, errors like "**Property 'addPackagesBundles' does not exist on type 'ProjectConfig'**" – praveen kumar Feb 28 '17 at 09:54
0
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
    ...
    }
praveen kumar
  • 1,474
  • 4
  • 13
  • 19