简体   繁体   中英

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?

使用:

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

I also got the same error, so use:

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

instead of:

import io from 'socket.io-client';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM