Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io-client - TypeError: socket_io_client_1.default is not a function

I've got socket.io-client installed in an Angular 5.2 application, and after following the steps to connect (which worked before for me, many times) I'm getting a weird error.

TypeError: socket_io_client_1.default is not a function
    at new AuthService (auth.service.ts:15)
    at _createClass (core.js:10891)
    at _createProviderInstance$1 (core.js:10865)
    at resolveNgModuleDep (core.js:10850)
    at NgModuleRef_.get (core.js:12087)
    at resolveDep (core.js:12577)
    at createClass (core.js:12439)
    at createDirectiveInstance (core.js:12284)
    at createViewNodes (core.js:13742)
    at callViewAction (core.js:14176)

Here's to 15th line in AuthService

import {Injectable} from '@angular/core';
import io from 'socket.io-client';
import {CookieService} from 'ngx-cookie-service';


@Injectable()
export class AuthService {
  socket;
  domain = 'http://localhost:3000';
  isUserLoggedIn = false;
  cookie_key = '';
  user = {};

  constructor(private cookieService: CookieService) {
    this.socket = io(this.domain);
  }

No idea what's going on at this point. Any pointers?

like image 596
filipbarak Avatar asked Feb 23 '18 14:02

filipbarak


2 Answers

Use:

import * as io from 'socket.io-client'
like image 189
Mike Avatar answered Sep 17 '22 14:09

Mike


I also got the same error, so use:

import * as io from 'socket.io-client' 

instead of:

import io from 'socket.io-client';
like image 31
pradep b Avatar answered Sep 18 '22 14:09

pradep b