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?
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?
Share Improve this question asked Feb 23, 2018 at 14:55 filipbarakfilipbarak 1,9052 gold badges19 silver badges30 bronze badges 5-
8
Try
import * as io from 'socket.io-client';
. – Striped Commented Feb 23, 2018 at 15:04 - That worked. Huh. Thanks! – filipbarak Commented Feb 26, 2018 at 9:58
- Glad to help :) – Striped Commented Feb 26, 2018 at 9:59
-
or use
esnext
module pilation in your typescript config. – S.. Commented Mar 17, 2019 at 11:18 -
@Striped do you know why
* as io
works butio
doesn't? – Juan Perez Commented Jan 6, 2023 at 19:07
2 Answers
Reset to default 11Use:
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';