ブラウザでIonic v3.14.0ハイブリッドアプリを実行しようとしたとき、「Cordova is undefined」というランタイムエラーが発生しました。私は上記のIonic 2ランタイムエラー:Cordovaが定義されていません
ionic cordova platform add browser
ionic cordova run browser
最初のコマンドは、その下に私のプロジェクトやフォルダ構造にPlatforms/browser
を追加し、私はPlatforms/browser/www
下cordova.js
を見つけることができますコマンドthisポストの答えを踏襲し、以下を実行しました。 しかし、上記の2番目のコマンドを実行すると、空のクロムブラウザのインスタンスが開きます(デフォルトはIEですが)、アプリを表示せずに空白のままになります。以下は端末からのスタックトレースです。上記であるから データservice.ts
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
declare let cordova:any;
/*
Generated class for the DataServiceProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class DataServiceProvider {
indexSpecs:any[];
soupName = "menuItems";
constructor(public http: Http) {
console.log('Hello DataServiceProvider Provider');
}
getMainMenu(){
return this.http.get('assets/data/mainmenu.json')
.map((response:Response)=>response.json().Categories);
}
getMainMenuItems() {
this.registerSmartStoreSoup();
}
registerSmartStoreSoup() {
this.indexSpecs = [{path:"Name",type:"string"},{path:"Id",type:"string"}];
cordova.require("com.salesforce.plugin.smartstore").registerSoup(this.soupName,this.indexSpecs,this.successCallback,this.errorCallback);
}
successCallback() {
console.log("Soup "+this.soupName+" Created Successfully");
}
errorCallback(err) {
console.log("Error Creating "+this.soupName+":"+err)
}
}
getMainMenuItems():
PS C:\Data\Per\Biz\Ionic\MyApp> ionic cordova run browser
Running app-scripts build: --platform browser --target cordova
[00:47:27] build dev started ...
[00:47:27] clean started ...
[00:47:27] clean finished in 12 ms
[00:47:27] copy started ...
[00:47:27] deeplinks started ...
[00:47:28] deeplinks finished in 113 ms
[00:47:28] transpile started ...
[00:47:31] transpile finished in 3.71 s
[00:47:31] preprocess started ...
[00:47:31] preprocess finished in 1 ms
[00:47:31] webpack started ...
[00:47:32] copy finished in 4.39 s
[00:47:41] webpack finished in 9.49 s
[00:47:41] sass started ...
[00:47:42] sass finished in 1.40 s
[00:47:42] postprocess started ...
[00:47:42] postprocess finished in 16 ms
[00:47:42] lint started ...
[00:47:42] build dev finished in 15.21 s
> cordova run browser
Error loading cordova-browser
Running command: cmd "/s /c "C:\Data\Per\Biz\Ionic\MyApp\platforms\browser\cordova\build.bat""
Cleaning Browser project
[00:47:46] lint finished in 4.18 s
Running command: cmd "/s /c "C:\Data\Per\Biz\Ionic\MyApp\platforms\browser\cordova\run.bat --nobuild""
Static file server running @ http://localhost:8000/index.html
CTRL + C to shut down
200 /index.html (gzip)
200 /cordova.js (gzip)
200 /build/main.js (gzip)
200 /build/polyfills.js (gzip)
200 /build/main.css (gzip)
200 /cordova_plugins.js (gzip)
200 /plugins/cordova-plugin-device/www/device.js (gzip)
200 /plugins/cordova-plugin-device/src/browser/DeviceProxy.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.oauth.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.network.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.sdkinfo.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.smartstore.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.smartstore.client.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.sfaccountmanager.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.plugin.smartsync.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.util.bootstrap.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.util.event.js (gzip)
200 /plugins/ionic-plugin-keyboard/www/browser/keyboard.js
200 /plugins/com.salesforce/www/com.salesforce.util.exec.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.util.logger.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.util.promiser.js (gzip)
200 /plugins/com.salesforce/www/com.salesforce.util.push.js (gzip)
200 /plugins/cordova-plugin-splashscreen/www/splashscreen.js (gzip)
200 /plugins/cordova-plugin-splashscreen/src/browser/SplashScreenProxy.js (gzip)
200 /config.xml (gzip)
404 /screen
200 /build/vendor.js (gzip)
200 /assets/icon/favicon.ico (gzip)
私は以下
私はコルドバを宣言した私のTSファイルをしているのindex.htmlで<script src="cordova.js"></script>
が含まれていますのコンストラクタで呼び出されます。app.component.ts
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public dataService: DataServiceProvider) {
this.initializeApp();
this.dataService.getMainMenuItems();
上記のスタックトレースで出力"Error loading cordova-browser"
が疑わしいです。しかし、ここで問題の確かなことはありません。誰かが私を助けてください、私はしばらくここで打たれます。
ブラウザでアプリケーションを実行しようとしていますか? ionic serveコマンドを試してください –
@PrithiviRaj:あなたの応答に感謝します。私は 'ionic serve'を実行しようとすると' Runtime Error: 'コードバスが定義されていません。 – Nat
私は、Cordova 6.5.0にアップグレードすることで、スタックトレースに「コードローダーの読み込みエラー」という問題が発生しました。しかし、私は 'ionic cordova run browser'を試しても、まだChromeに空白のページが表示されています – Nat