【问题标题】:Socket.io-client - TypeError: socket_io_client_1.default is not a functionSocket.io-client - TypeError: socket_io_client_1.default 不是函数
【发布时间】:2018-08-03 16:04:39
【问题描述】:

我在 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);
  }

现在不知道发生了什么。有什么指点吗?

【问题讨论】:

  • 试试import * as io from 'socket.io-client';
  • 那行得通。嗯。谢谢!
  • 很高兴为您提供帮助:)
  • 或者在你的 typescript 配置中使用 esnext 模块编译。

标签: javascript angular typescript socket.io


【解决方案1】:

用途:

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

【讨论】:

    【解决方案2】:

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

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

    代替:

    import io from 'socket.io-client';
    

    【讨论】:

      猜你喜欢
      • 2019-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-10
      • 2016-09-20
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多