Skip to content

Library socket.io-client is not compatible with latest Angular 6 #1206

@jameskentTX

Description

@jameskentTX

I want to:

  • report a bug - solved, look last two lines for workaround

Library socket.io-client is not compatible with latest Angular 6. There is error at execution time:

ReferenceError: global is not defined at Object../node_modules/socket.io-client/node_modules/socket.io-parser/is-buffer.js (is-buffer.js:4)

Please read comment below to know more:
angular/angular-cli#9827 (comment)

If you want to see this error for yourself, add to angular 6.0 app simple service like that below:

import { Injectable } from 'angular/core';
import * as socketIo from 'socket.io-client';

@Injectable()
export class SocketService {
    private socket;

    constructor() {}

    public initSocket(): void {
        this.socket = socketIo();
    }
}

Error disappears when you remove initSocket function.



Ok, there is workaround in Angular 6 to work with socket.io-client.
Add (window as any).global = window; to polyfills.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions