我正在尝试将去年用ionic 2制作的项目迁移到ionic 3.9。
我在使用离子型天然硅橡胶时遇到了麻烦。
我更新了CLI,并按照此处提到的步骤进行了更新:https://forum.ionicframework.com/t/guide-how-to-update-to-ionic-3-x/87516
我认为我做了文档中提到的内容。我将此导入添加到了app.module.ts
文件中:
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
然后在NgModule的providers条目中添加了2个对象:
@NgModule({
// ...
providers: [
StatusBar,
SplashScreen,
SQLite, SQLiteObject,
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
此外,我有1个包含sqlite对象的类,并且我将其替换为:
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
上次导入是:
import { SQLite } from 'ionic-native';
不幸的是,当我尝试使用ionic cordova build android
进行构建时,我得到了:
// ...
[18:34:51] preprocess finished in 1 ms
[18:34:51] webpack started ...
[18:34:54] copy finished in 10.43 s
[18:34:59] ionic-app-script task: "build"
[18:34:59] Error: ./src/pages/home/home.ts Module not found: Error: Can't resolve '@ionic-native/file' in
'/Users/julianlecalvez/Documents/SFR/biometo-v4/src/pages/home' resolve '@ionic-native/file' in
'/Users/julianlecalvez/Documents/SFR/biometo-v4/src/pages/home' Parsed request is a module using description
file: /Users/julianlecalvez/Documents/SFR/biometo-v4/package.json (relative path: ./src/pages/home) Field
'browser' doesn't contain a valid alias configuration after using description file:
/Users/julianlecalvez/Documents/SFR/biometo-v4/package.json (relative path: ./src/pages/home) resolve as
module looking for modules in /Users/julianlecalvez/Documents/SFR/biometo-v4/node_modules using description
file: /Users/julianlecalvez/Documents/SFR/biometo-v4/package.json (relative path: ./node_modules)
// I got the same errors for other native plugins (File & Google Analytics)
这是我的ionic info
:
我
onic:
ionic (Ionic CLI) : 4.3.1 (/usr/local/lib/node_modules/ionic)
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 : android 6.0.0, ios 4.3.1
Cordova Plugins : no whitelisted plugins (11 plugins total)
System:
Android SDK Tools : 25.1.3 (/Users/julianlecalvez/Library/Android/sdk/)
ios-deploy : 1.9.1
NodeJS : v8.9.1 (/usr/local/bin/node)
npm : 5.5.1
OS : macOS High Sierra
这是我的package.json
:
{
"name": "xxx",
"author": "xxx",
"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",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26",
"@types/hammerjs": "^2.0.34",
"cordova-android": "7.1.1",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.2.0",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-sqlite-storage": "2.5.1",
"prismic.io": "^3.3.0"
},
"devDependencies": {
"@ionic/app-scripts": "^3.2.0",
"typescript": "~2.6.2"
},
"cordovaPlugins": [
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-whitelist",
"cordova-plugin-console",
"ionic-plugin-keyboard",
"cordova-plugin-splashscreen"
],
"cordovaPlatforms": [
"ios",
{
"platform": "ios",
"version": "",
"locator": "ios"
}
],
"description": "xxx",
"cordova": {
"plugins": {
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-sqlite-storage": {}
}
}
}
答案 0 :(得分:0)
在安装ionic插件时,如果不指定版本,它将安装最新版本。但是最新版本适用于ionic4,因此您不能在ionic3中使用它,因此必须通过指定版本安装@ ionic-native pulgin。
请参阅ionic3的插件文档,而不是ionic4或5。