Socket.io-client - TypeError:socket_io_client_1.default不是函数

时间:2018-02-23 14:55:07

标签: javascript angular typescript socket.io

我已经在Angular 5.2应用程序中安装了socket.io-client,并且在按照连接步骤(之前为我工作了很多次)之后,我发现了一个奇怪的错误。

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)

这里是AuthService

中的第15行
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);
  }

不知道此时发生了什么。有什么指针吗?

2 个答案:

答案 0 :(得分:1)

使用:

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

答案 1 :(得分:0)

我也遇到了同样的错误,所以使用:

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

代替:

import io from 'socket.io-client';