2017-05-03 253 views
3

我有我的離子二期工程在我的Linux任務時,我和應對移動到具有離子的MAC 3離子3:類型「任何」不是一個構造函數類型

所以我創造了一個新的項目,用新項目替換頁面,提供,組件文件夾我得到像cannot find module "ionic-native"錯誤後導入我的插件到app.modulte.ts文件我得到錯誤,因爲'類型'任何'不是構造函數類型。'

我的終端顯示

17:39:48] typescript: node_modules/@ionic-native/app-version/index.d.ts, line: 25 
      Type 'any' is not a constructor function type. [17:39:48] typescript: node_modules/@ionic-native/geolocation/index.d.ts, line: 127 [17:39:48] typescript: node_modules/@ionic-native/google-analytics/index.d.ts, line: 30 [17:39:48] typescript: node_modules/@ionic-native/network/index.d.ts, line: 49 [17:39:48] typescript: node_modules/@ionic-native/sms/index.d.ts, line: 41 [17:39:48] typescript: node_modules/@ionic-native/social-sharing/index.d.ts, line: 29 [17:39:48] typescript: node_modules/@ionic-native/sqlite/index.d.ts, line: 115 

     L25: export declare class AppVersion extends IonicNativePlugin { 

      Type 'any' is not a constructor function type. 

    L127: export declare class Geolocation extends IonicNativePlugin { 

      Type 'any' is not a constructor function type. 

     L30: export declare class GoogleAnalytics extends IonicNativePlugin { 

      Type 'any' is not a constructor function type. 

     L49: export declare class Network extends IonicNativePlugin { 

      Type 'any' is not a constructor function type. 

     L41: export declare class SMS extends IonicNativePlugin { 

      Type 'any' is not a constructor function type. 

     L29: export declare class SocialSharing extends IonicNativePlugin { 

      Type 'any' is not a constructor function type. 

    L115: export declare class SQLite extends IonicNativePlugin { 

[17:39:48] dev server running: http://localhost:8100/ 
在我的BR

owser我收到錯誤,如this

這裏是我的package.json文件

{ 
    "name": "ionic-hello-world", 
    "version": "0.0.0", 
    "author": "Ionic Framework", 
    "homepage": "http://ionicframework.com/", 
    "private": true, 
    "scripts": { 
    "clean": "ionic-app-scripts clean", 
    "build": "ionic-app-scripts build", 
    "ionic:build": "ionic-app-scripts build", 
    "ionic:serve": "ionic-app-scripts serve" 
    }, 
    "dependencies": { 
    "@angular/common": "4.0.2", 
    "@angular/compiler": "4.0.2", 
    "@angular/compiler-cli": "4.0.2", 
    "@angular/core": "4.0.2", 
    "@angular/forms": "4.0.2", 
    "@angular/http": "4.0.2", 
    "@angular/platform-browser": "4.0.2", 
    "@angular/platform-browser-dynamic": "4.0.2", 
    "@ionic-native/app-version": "^3.6.1", 
    "@ionic-native/geolocation": "^3.6.1", 
    "@ionic-native/google-analytics": "^3.6.1", 
    "@ionic-native/network": "^3.6.1", 
    "@ionic-native/sms": "^3.6.1", 
    "@ionic-native/social-sharing": "^3.6.1", 
    "@ionic-native/splash-screen": "3.4.2", 
    "@ionic-native/sqlite": "^3.6.1", 
    "@ionic-native/status-bar": "3.4.2", 
    "@ionic/storage": "2.0.1", 
    "ionic-angular": "3.1.1", 
    "ionicons": "3.0.0", 
    "rxjs": "5.1.1", 
    "sw-toolbox": "3.4.0", 
    "zone.js": "^0.8.5" 
    }, 
    "devDependencies": { 
    "@ionic/app-scripts": "1.3.6", 
    "typescript": "~2.2.1" 
    }, 
    "cordovaPlugins": [ 
    "cordova-plugin-whitelist", 
    "cordova-plugin-statusbar", 
    "cordova-plugin-console", 
    "cordova-plugin-device", 
    "cordova-plugin-splashscreen", 
    "ionic-plugin-keyboard", 
    "cordova-plugin-android-permissions", 
    "cordova-plugin-app-version", 
    "cordova-plugin-geolocation", 
    "cordova-plugin-google-analytics", 
    "cordova-plugin-network-information", 
    "cordova-plugin-sms", 
    "cordova-plugin-x-socialsharing", 
    "cordova-sqlite-storage" 
    ], 
    "cordovaPlatforms": [ 
    "ios", 
    { 
     "platform": "ios", 
     "version": "", 
     "locator": "ios" 
    } 
    ], 
    "description": "kmart: An Ionic project" 
} 

使用npm install @ionic-native/core --save我收到錯誤,如this

回答

10

要使用ionic-native 3.x中,您需要安裝@ionic-native/core後。

npm install @ionic-native/[email protected] --save 
+0

我越來越像錯誤無法安裝 –

+0

我試過這個命令'npm install @ ionic-native/core --save'如果我使用這個命令我得到錯誤,如'無法找到模塊「ionic-native」' –

+0

你可以添加完整的錯誤消息質疑嗎? –

1

我在我的package.json中有@ionic-native/core ^3.6.0。對我來說,這個問題是通過導入我的插件,像

import {File, Transfer, FilePath} from "ionic-native"; 

,而不是

import {FilePath} from "@ionic-native/file-path"; 
import {Transfer} from "@ionic-native/transfer"; 
import {File} from "@ionic-native/file"; 
0

昨天我更新我很老的版本到一個新的後,面臨着同樣的問題解決了。 我不得不執行很多步驟才能使其工作。這是我需要做的,或者我是如何解決它的。 首先我創建了一個「虛擬」的項目

ionic start myApp tabs 

我打開package.json和比較所有的版本我目前的一個,並相應地更新它們(您可能需要使用npm outdated看到最新的和已安裝的版本)。

不幸的是,沒有解決我的問題,我可以建立我的項目,但我得到了像你一樣的錯誤cannot find module "ionic-native" 開始後。

閱讀了很多帖子和提示後,我做了以下(有很多其他錯誤來了,這就是我解決所有這些問題)。

打開app.module.ts和檢查進口
前:

imports: [ 
    IonicModule.forRoot(MyApp), 
    Ionic2RatingModule 
] 

後:

imports: [ 
    BrowserModule, 
    IonicModule.forRoot(MyApp), 
    Ionic2RatingModule, 
    HttpModule /* in case you used http before */ 
] 

下一個重要步驟是尋找你的整個代碼
import from "ionic-native"

如果你發現這種情況,你必須改變/更新爲新版本。 (通常用於app.component中的splashScreen和statusBar。TS)

前:

import { StatusBar, Splashscreen } from 'ionic-native'; 
@Component({ 
    templateUrl: 'app.html' 
}) 
export class MyApp { 
    rootPage = HomePage;  
    constructor(platform: Platform) { 
    platform.ready().then(() => { 
     // Okay, so the platform is ready and our plugins are available. 
     // Here you can do any higher level native things you might need. 
     StatusBar.styleDefault(); 
     Splashscreen.hide(); 
    }); 
    platform.pause.subscribe(e=>{ 

    }) 
    } 
} 

後:

import {StatusBar} from "@ionic-native/status-bar"; 
import {SplashScreen} from "@ionic-native/splash-screen"; 
    @Component({ 
    templateUrl: 'app.html' 
    }) 
    export class MyApp { 
    rootPage = HomePage; 

    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { 
     platform.ready().then(() => { 
     // Okay, so the platform is ready and our plugins are available. 
     // Here you can do any higher level native things you might need. 
     statusBar.styleDefault(); 
     splashScreen.hide(); 
     }); 
     platform.pause.subscribe(e => { 

     }) 
    } 
    } 

檢查構造函數和進口,他們改變了! 我不得不這樣做,其經MODULE import from "ionic-native"進口同類例如用於一切所有這些變化:StatusBar, SplashScreen, Camera, Network, Transfer, Geolocation ... 也請記住,現在你必須將它們添加到providers部分在app.module.ts
如果你不能找到一個模塊了(喜歡它發生在我身上的攝像頭),請確保您導入正確的離子模塊npm install --save @ionic-native/camera
在最後,你不應該再在你的代碼中找到任何
MODULE import from "ionic-native"
。 希望它有助於某人:)