Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: error TS2307: Cannot find module 'socket.io-client'

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

like image 828
Jils Avatar asked Aug 30 '16 11:08

Jils


1 Answers

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:

npm i socket.io-client @types/socket.io-client 

outdated:

You are missing typings. Open typings.d.ts and add

declare module 'socket.io-client' {
  var e: any;
  export = e;
}

You 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.

like image 125
j2L4e Avatar answered Oct 25 '22 20:10

j2L4e