sclausen / ngx-mqtt

This library isn't just a wrapper around MQTT.js for angular. It uses observables and takes care of subscription handling and message routing.
https://sclausen.github.io/ngx-mqtt/
MIT License
186 stars 83 forks source link

ERROR RuntimeError: NG0200: Circular dependency in DI detected for MqttService. #207

Open Kumaravel-A opened 2 years ago

Kumaravel-A commented 2 years ago

Current behavior

Mqtt is working fine in normal angular application but after adding angular universal for meta purpose. I got this error circular dependency.

Expected behavior

Minimal working example of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


ngx-mqtt version: 9.0.5


- Broker 

Others:

mvadrev commented 2 years ago

I am having this same issue. Any help will be appreciated.

` //app.module.ts import { MqttModule, IMqttServiceOptions } from "ngx-mqtt";

export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = { hostname: 'a1oldy8v49q6jl-ats.iot.us-east-1.amazonaws.com', port: 9001, path: '/mqtt' } also added to imports `

In component if I just put the import in the constructor I get the error in my chrome console. Angular complies at command line level though.

constructor(private mqtt: MqttService) { }

Error:

core.mjs:6461 ERROR Error: NG0200: Circular dependency in DI detected for MqttService. Find more at https://angular.io/errors/NG0200 at throwCyclicDependencyError (core.mjs:220:1) at R3Injector.hydrate (core.mjs:11431:1) at R3Injector.get (core.mjs:11251:1) at NgModuleRef.get (core.mjs:21807:1) at Object.get (core.mjs:21484:1) at lookupTokenUsingModuleInjector (core.mjs:3334:1) at getOrCreateInjectable (core.mjs:3446:1) at Module.ɵɵdirectiveInject (core.mjs:14381:1) at NodeInjectorFactory.ExperimentsComponent_Factory [as factory] (experiments.component.ts:10:34) at getNodeInjectable (core.mjs:3541:1) defaultErrorLogger @ core.mjs:6461 handleError @ core.mjs:6508 (anonymous) @ core.mjs:26428 invoke @ zone.js:372 run @ zone.js:134 runOutsideAngular @ core.mjs:25356 tick @ core.mjs:26428 (anonymous) @ core.mjs:26273 invoke @ zone.js:372 onInvoke @ core.mjs:25457 invoke @ zone.js:371 run @ zone.js:134 run @ core.mjs:25311 next @ core.mjs:26272 (anonymous) @ Subscriber.js:110 _next @ Subscriber.js:60 next @ Subscriber.js:31 (anonymous) @ Subject.js:31 errorContext @ errorContext.js:19 next @ Subject.js:26 emit @ core.mjs:22402 checkStable @ core.mjs:25379 onHasTask @ core.mjs:25474 hasTask @ zone.js:426 _updateTaskCount @ zone.js:447 _updateTaskCount @ zone.js:274 runTask @ zone.js:195 drainMicroTaskQueue @ zone.js:585 Promise.then (async) nativeScheduleMicroTask @ zone.js:561 scheduleMicroTask @ zone.js:572 scheduleTask @ zone.js:396 scheduleTask @ zone.js:221 scheduleMicroTask @ zone.js:241 scheduleResolveOrReject @ zone.js:1265 then @ zone.js:1450 bootstrapModule @ core.mjs:26055 4431 @ main.ts:11 __webpack_require__ @ bootstrap:19 __webpack_exec__ @ main.ts:12 (anonymous) @ main.ts:12 __webpack_require__.O @ chunk loaded:23 (anonymous) @ main.ts:12 webpackJsonpCallback @ jsonp chunk loading:34 (anonymous) @ main.js:2 core.mjs:6461 ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[MqttService -> InjectionToken NgxMqttServiceConfig -> InjectionToken NgxMqttServiceConfig -> InjectionToken NgxMqttServiceConfig]: NullInjectorError: No provider for InjectionToken NgxMqttServiceConfig! NullInjectorError: R3InjectorError(AppModule)[MqttService -> InjectionToken NgxMqttServiceConfig -> InjectionToken NgxMqttServiceConfig -> InjectionToken NgxMqttServiceConfig]: NullInjectorError: No provider for InjectionToken NgxMqttServiceConfig! at NullInjector.get (core.mjs:11095:1) at R3Injector.get (core.mjs:11262:1) at R3Injector.get (core.mjs:11262:1) at R3Injector.get (core.mjs:11262:1) at injectInjectorOnly (core.mjs:4741:1) at Module.ɵɵinject (core.mjs:4745:1) at Object.MqttService_Factory [as factory] (ngx-mqtt.js:373:121) at R3Injector.hydrate (core.mjs:11435:1) at R3Injector.get (core.mjs:11251:1) at NgModuleRef.get (core.mjs:21807:1) at resolvePromise (zone.js:1211:1) at resolvePromise (zone.js:1165:1) at zone.js:1278:1 at _ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25444:1) at _ZoneDelegate.invokeTask (zone.js:405:1) at Zone.runTask (zone.js:178:1) at drainMicroTaskQueue (zone.js:585:1)