After having installed the module socket.io
npm install socket.io --save
I have the following error:
error TS2307: Cannot find module 'socket.io-client'
import
import * as io from 'socket.io-client';
systemjs.config.js
var map = {
'socket.io-client': 'node_modules/socket.io-client/socket.io.js'
}
var packages = {
'socket.io-client': { main: 'socket.io', format: 'cjs', defaultExtension: 'js' }
}
package.json
"dependencies": {
"socket.io": "^1.4.8"
}
typings.d.ts
/// <reference path="../socket.io-client/socket.io.js" />
declare module 'socket.io-client' {
var e: any;
export = e;
}
socket.io-client (Directory)
– socket.io.js
– typings.d.ts
Angular 2 RC5
Best Answer
Update 2021
@nullromo pointed out, the socket.io-client package now has typings built-in. Installing the types separately is no longer necessary
Update 2018
To properly use socket.io in the browser you need to install both the socket.io client package and its typings:
outdated:
You are missing typings. Open
typings.d.ts
and addYou can also try to install typings for socket.io via
npm i @types/socket.io-client
. I don't know if there are typings available, though.