我有一个 Ionic 2 应用程序,它运行良好,但不久前我安装了失眠插件,现在我无法构建生产版本!
如果我这样做: $ionic run android
或$ionic run android --consolelogs --livereload
,它工作得很好,失眠症工作得很好。
但是,现在当我这样做时:
$ionic build android --prod --release
我得到:
build prod failed: Cannot read property 'Plugin' of undefined, resolving symbol Insomnia in /media/....blabla.../node_modules/@ionic-native/insomnia/index.d.ts
我按照官方文档的步骤进行操作。(失眠插件(
提前非常感谢!!
编辑:
当我安装失眠插件时,我有这个,但我没有重视,因为我以前得到过它:
├── @ionic-native/insomnia@3.4.4
└── UNMET PEER DEPENDENCY rxjs@5.0.1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN @angular/core@2.2.1 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN @angular/http@2.2.1 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN ionic-angular@2.1.0 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
packaje.json:
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic-native/core": "^3.4.4",
"@ionic-native/insomnia": "^3.4.4",
"@ionic/storage": "1.1.7",
"angular2-fullcalendar": "^1.1.1",
"angularfire2": "^2.0.0-beta.6-preview",
"firebase": "^3.6.4",
"ionic-angular": "^2.1.0",
"ionic-native": "^2.5.1",
"ionicons": "3.0.0",
"jquery-ui": "^1.12.1",
"rxjs": "^5.0.1",
"soundcloud": "^3.1.2",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.3",
"typescript": "2.0.9"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "Mindfulness: An Ionic project"
}
配置.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.mindfulness924927" version="0.0.55" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Visión Clara</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
<content src="index.html"/>
<access origin="*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
<platform name="android">
<allow-intent href="market:*"/>
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png"/>
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png"/>
<icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png"/>
<icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png"/>
<icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png"/>
<icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png"/>
<splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png"/>
<splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png"/>
<splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png"/>
<splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png"/>
<splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png"/>
<splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png"/>
<splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png"/>
<splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png"/>
<splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png"/>
<splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png"/>
<splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png"/>
<splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png"/>
</platform>
<platform name="ios">
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="android-minSdkVersion" value="19"/>
<preference name="BackupWebStorage" value="none"/>
<preference name="SplashMaintainAspectRatio" value="true"/>
<preference name="FadeSplashScreenDuration" value="300"/>
<preference name="SplashScreen" value="screen"/>
<preference name="SplashScreenDelay" value="3000"/>
<preference name="loadUrlTimeoutValue" value="700000"/>
<preference name="orientation" value="portrait"/>
<feature name="StatusBar">
<param name="ios-package" onload="true" value="CDVStatusBar"/>
</feature>
<allow-navigation href="http://192.168.1.10:8000"/>
<allow-navigation href="http://192.168.0.47:8000"/>
<allow-navigation href="http://192.168.120.57:8000"/>
<allow-navigation href="http://192.168.120.54:8000"/>
<allow-navigation href="http://192.168.120.60:8000"/>
<allow-navigation href="http://192.168.120.51:8000"/>
<allow-navigation href="http://192.168.120.53:8000"/>
<allow-navigation href="http://192.168.120.52:8000"/>
<allow-navigation href="http://192.168.120.55:8000"/>
<allow-navigation href="http://192.168.120.54:8100"/>
<allow-navigation href="http://192.168.1.10:8100"/>
<allow-navigation href="http://192.168.43.177:8100"/>
<allow-navigation href="http://192.168.0.47:8100"/>
<allow-navigation href="http://192.168.120.55:8100"/>
<allow-navigation href="http://192.168.120.50:8100"/>
<plugin name="cordova-sqlite-storage" spec="~2.0.1"/>
<plugin name="cordova-plugin-network-information" spec="~1.3.1"/>
<plugin name="cordova-plugin-http" spec="~1.2.0"/>
<plugin name="cordova-plugin-media" spec="~2.4.1"/>
<plugin name="cordova-plugin-file" spec="~4.3.1"/>
<icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
</widget>
编辑2:
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic-native/core": "^3.4.4",
"@ionic-native/facebook": "^3.4.4",
"@ionic-native/file": "^3.4.4",
"@ionic-native/in-app-purchase": "^3.4.4",
"@ionic-native/insomnia": "^3.4.4",
"@ionic-native/local-notifications": "^3.4.4",
"@ionic-native/media": "^3.4.4",
"@ionic-native/network": "^3.4.4",
"@ionic-native/screenshot": "^3.4.4",
"@ionic-native/social-sharing": "^3.4.4",
"@ionic-native/splash-screen": "^3.4.4",
"@ionic-native/status-bar": "^3.4.4",
"@ionic/storage": "1.1.7",
"angular2-fullcalendar": "^1.1.1",
"angularfire2": "^2.0.0-beta.6-preview",
"firebase": "^3.6.4",
"ionic-angular": "^2.1.0",
"ionicons": "3.0.0",
"jquery-ui": "^1.12.1",
"rxjs": "^5.0.1",
"soundcloud": "^3.1.2",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.3",
"typescript": "2.0.9"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "Mindfulness: An Ionic project"
}
你的问题就在这里"ionic-native": "^2.5.1",
.您必须将其从package.json
文件中删除,然后运行npm i
.您不能同时保留最新的"@ionic-native/core": "^3.4.4",
和旧的。您没有正确升级本机模块。所以现在你必须如上所述。在此之前,请保留项目的备份。
您必须将插件实现为providers
。请参阅此文档。
更新:
卸载
cordova plugin remove cordova-plugin-statusbar --save
npm uninstall @ionic-native/status-bar --save
安装
ionic plugin add cordova-plugin-statusbar --save
npm install --save @ionic-native/status-bar
我遇到了同样的错误,并解决了它更新 Angular 依赖项,如下所示:
"dependencies": {
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"@ionic-native/calendar": "^3.4.4",
"@ionic-native/contacts": "^3.4.4",
"@ionic-native/core": "^3.4.4",
"@ionic-native/google-plus": "^3.4.4",
"@ionic-native/keyboard": "^3.4.4",
"@ionic-native/splash-screen": "^3.4.4",
"@ionic/storage": "1.1.7",
"angularfire2": "^2.0.0-beta.8",
"chance": "^1.0.6",
"firebase": "^3.7.4",
"ionic-angular": "2.3.0",
"ionicons": "3.0.0",
"moment": "^2.18.1",
"ng2-translate": "^5.0.0",
"rxjs": "^5.0.1",
"sw-toolbox": "3.4.0",
"uglify-js": "^2.8.22",
"underscore": "^1.8.3",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.4",
"@types/gapi": "0.0.30",
"typescript": "2.0.9"
},