找不到模块'@ ionic-native / power-management / ngx'

问题描述 投票:0回答:1

我在我的离子应用程序中安装了cordova电源管理插件。按照使用指南“https://ionicframework.com/docs/native/power-management#installationenter link description here”,我导入如下类:

import { PowerManagement } from '@ionic-native/power-management/ngx';

但是,当构建这个离子应用程序时,得到错误:

找不到模块'@ ionic-native / power-management / ngx'

为什么会出现此错误?怎么解决?

我尝试通过删除ngx模块导入类,然后错误消失:

import { PowerManagement } from '@ionic-native/power-management';

我的package.json文件是:

{
  "name": "ionicapp",
  "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",
    "@angular/router": "^6.1.9",
    "@ionic-native/background-geolocation": "^4.16.0",
    "@ionic-native/background-mode": "^4.20.0",
    "@ionic-native/ble": "^4.12.0",
    "@ionic-native/bluetooth-serial": "^4.12.2",
    "@ionic-native/camera": "4.3.3",
    "@ionic-native/core": "^4.12.2",
    "@ionic-native/geolocation": "^4.12.0",
    "@ionic-native/google-maps": "^4.12.0",
    "@ionic-native/launch-navigator": "^4.15.0",
    "@ionic-native/native-storage": "^4.12.0",
    "@ionic-native/network": "^4.12.2",
    "@ionic-native/network-interface": "^4.12.2",
    "@ionic-native/power-management": "^4.20.0",
    "@ionic-native/splash-screen": "~4.11.0",
    "@ionic-native/sqlite": "^4.12.2",
    "@ionic-native/status-bar": "^4.11.0",
    "@ionic/storage": "^2.1.3",
    "@ngx-translate/core": "8.0.0",
    "@ngx-translate/http-loader": "^2.0.0",
    "@types/google-maps": "^3.2.0",
    "@types/googlemaps": "^3.30.12",
    "an": "0.0.8",
    "angularfire2": "^5.0.2",
    "chart.js": "^2.7.2",
    "cordova-android": "7.1.0",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-background-mode": "git+https://github.com/tushe/cordova-plugin-background-mode.git",
    "cordova-plugin-ble-central": "^1.2.2",
    "cordova-plugin-bluetooth-serial": "^0.4.7",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-dialogs": "^2.0.1",
    "cordova-plugin-geolocation": "^4.0.1",
    "cordova-plugin-googlemaps": "^2.4.2",
    "cordova-plugin-ionic-keyboard": "^2.1.2",
    "cordova-plugin-ionic-webview": "^2.1.0",
    "cordova-plugin-mauron85-background-geolocation": "^3.0.0-alpha.43",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-networkinterface": "^2.0.0",
    "cordova-plugin-powermanagement-orig": "^1.1.2",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-sqlite-storage": "^2.4.0",
    "firebase": "^5.5.3",
    "ionic-angular": "3.9.2",
    "ionic-native": "4.1.1",
    "ionicons": "3.0.0",
    "ng2-charts": "^1.6.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "uk.co.workingedge.phonegap.plugin.launchnavigator": "^4.2.2",
    "zone.js": "0.8.26",
    "at.gofg.sportscomputer.powermanagement": "~1.1.2"
  },
    "devDependencies": {
    "@ionic/app-scripts": "^3.2.0",
    "@mauron85/cordova-plugin-background-geolocation": "^3.0.0-alpha.4",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
     "plugins": {
      "cordova-plugin-ble-central": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-geolocation": {
        "GEOLOCATION_USAGE_DESCRIPTION": "To locate you"
      },
      "cordova-plugin-mauron85-background-geolocation": {
        "GOOGLE_PLAY_SERVICES_VERSION": "11+",
        "ANDROID_SUPPORT_LIBRARY_VERSION": "23+",
        "ALWAYS_USAGE_DESCRIPTION": "App requires background tracking enabled",
        "MOTION_USAGE_DESCRIPTION": "App requires motion detection"
      },
      "cordova-plugin-nativestorage": {},
      "cordova-sqlite-storage": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-bluetooth-serial": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-networkinterface": {},
      "uk.co.workingedge.phonegap.plugin.launchnavigator": {
        "OKHTTP_VERSION": "3.+"
      },
      "cordova-plugin-background-mode": {},
      "at.gofg.sportscomputer.powermanagement": {}
    },
    "platforms": [
      "android"
    ]
  }
}
ionic-framework cordova-plugins
1个回答
2
投票

如果您的Angular版本> = 6,请使用ngx

您似乎使用了错误的插件版本。按照以下步骤更正错误

检查ionic.config.json文件中的项目类型。

如果类型是“ionic-angular”,则安装4版本。

ionic cordova plugin add cordova-plugin-powermanagement-orig
npm install @ionic-native/power-management@4

如果类型为“angular”,则安装最新版本

ionic cordova plugin add cordova-plugin-powermanagement-orig
npm install @ionic-native/power-management

注意:

仅在使用Angular 6或6+时才在导入结束时添加ngx

import { PowerManagement } from '@ionic-native/power-management/ngx';

如果不是从app.module.ts和app.component.ts中的导入中删除ngx

import { PowerManagement } from '@ionic-native/power-management';

Refencence:https://github.com/ionic-team/ionic/issues/15225#issuecomment-414074074

© www.soinside.com 2019 - 2024. All rights reserved.