ngx-mqtt TypeError:__WEBPACK_IMPORTED_MODULE_0__angular_core __。defineInjectable不是函数

时间:2018-10-21 03:20:11

标签: ionic3 mqtt

我是Ionic 3的新手,我需要使用ngx-mqtt插件来订阅主题。不幸的是,当我安装插件时,我的app.module.ts中出现了此错误。我找不到该插件的详细教程。

在浏览器控制台中,错误显示在mqtt.service.js:385

这是我的离子信息:

Ionic:

   ionic (Ionic CLI)  : 4.2.1 
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : none
   Cordova Plugins       : no whitelisted plugins (1 plugins total)

System:

   Android SDK Tools : 26.1.1 
   ios-deploy        : 1.9.2
   NodeJS            : v6.9.2 
   npm               : 6.4.1
   OS                : macOS High Sierra
   Xcode             : Xcode 10.0 Build version 10A255

这是我的package.json:

{
  "name": "app",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/core": "~4.15.0",
    "@ionic-native/splash-screen": "~4.15.0",
    "@ionic-native/status-bar": "~4.15.0",
    "@ionic/storage": "^2.2.0",
    "cordova-sqlite-storage": "2.5.0",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "mqtt": "^2.18.8",
    "ngx-mqtt": "6.7.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.0",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-sqlite-storage": {}
    }
  }
}

这是我的app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { IonicStorageModule } from '@ionic/storage';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
// import { ListPage } from '../pages/list/list';
import { LoginPage } from '../pages/login/login';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

// MQTT
import { Observable } from 'rxjs/Observable';
import {
  // IMqttMessage,
  MqttModule,
  MqttService,
  IMqttServiceOptions
} from 'ngx-mqtt';

export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {
  hostname: 'wss://iot.eclipse.org',
  port: 443,
  path: '/ws'
};

export function mqttServiceFactory() {
  return new MqttService(MQTT_SERVICE_OPTIONS);
}

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    // ListPage,
    LoginPage
  ],
  imports: [
    BrowserModule,
    MqttModule.forRoot({
      hostname: 'wss://iot.eclipse.org',
      port: 443,
      path: '/ws'
    }),
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    // ListPage,
    LoginPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    // MqttService,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

1 个答案:

答案 0 :(得分:0)

我们发现,在Git repogini.iloc[0,4:] = pd.to_numeric(gini.iloc[0,4:], downcast = "integer", errors = "coerce")文件中,他们清楚地提到 ngx-mqtt> = 6仅与角度> = 6兼容,并且对于您的README.md文件,很显然您的项目的角度版本为 5.2.11 。因此,您需要使用相关的角度版本更新项目。

希望它会对您有所帮助。