I'm trying to use the socket.io client in my angular 2 app and installed it and typings
I'm just importing from 'socket.io-client';
but somehow I get tons of errors from that:
I can use the lib in my index.html if I load the script from a cdn and just put the init code in a <script>
tag but I can't use it in my actual angular 2 app.
What am I doing wrong here?
This is my boilerplate: https://github.com/mgechev/angular2-seed
The examples for socket.io seem outdated which is why I avoided them.
this is all i'm doing and already getting those errors:
import * as io from 'socket.io-client';
[...]
var socket = io('127.0.0.1');
So the issue seems to be related to SystemJS in someway. This https://github.com/mgechev/angular2-seed/wiki/Add-external-dependency suggests I can add the socket.io-client and it should add all dependencies automaticly that doesn't seem the case though.
I've tried the full example but that won't work either.
Im using socket.io client in my angular 2 application, and have no problems with it. First of all you should not put script
tag to socket.io-client in your index.hml
. Second you need these lines in your system.js configuration:
{
packages: {
"socket.io-client": {"defaultExtension": "js"}
},
map: {
"socket.io-client": "node_modules/socket.io-client/socket.io.js"
}
}
Then you simply use it:
import * as io from "socket.io-client";
io.connect(url, { /* ... */ });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With