vrn-dev / ng6-socket-io

Socket.IO module for Angular 6 and RxjS 6
MIT License
5 stars 11 forks source link

ERROR TypeError: Cannot read property 'runOutsideAngular' of undefined #5

Open jaymehtasa opened 5 years ago

jaymehtasa commented 5 years ago

app.module.ts

const config = {
  url: environment.socketUrl,
  options: {
    transportOptions: {
      polling: {
        extraHeaders: {
          authorization:
            `Bearer ${localStorage.getItem('token')}`,
        },
      },
    },
  },
};

// ...

imports: [
    SocketIoModule.forRoot(config)
]

socket.service.ts

@Injectable({
  providedIn: 'root',
})
export class SocketService {
  constructor(private socket: Socket) {}

  public emitSocket() {
    return this.socket;
  }
}

error

AppComponent.html:118 ERROR TypeError: Cannot read property 'runOutsideAngular' of undefined
    at new WrappedSocket (socket-io.service.js:29)
    at SocketFactory (socket-io.module.js:14)
    at _callFactory (core.js:21282)
    at _createProviderInstance (core.js:21238)
    at resolveNgModuleDep (core.js:21199)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:21907)
    at injectInjectorOnly (core.js:1774)
    at inject (core.js:1779)
    at injectArgs (core.js:1828)
    at core.js:15519

Angular

{
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
}
jaymehtasa commented 5 years ago

I found as soon as I inject Socket dependency injection in any service component, it throws this error.

bloublou2014 commented 5 years ago

Setting es2015 on tsconfig solved the problem on my side:

 "compilerOptions": {
 // ....
"lib": [
      "es2018",
      "dom"
    ],
    "target": "es2015"
}