2017-05-03 231 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"
。 希望它有助于某人:)