当我尝试在浏览器中运行我的Ionic v3.14.0混合应用程序时,我收到了运行时错误“Cordova未定义”。我按照this帖子的回答并运行了以下命令
ionic cordova platform add browser
ionic cordova run browser
上面的第一个命令将Platforms/browser
添加到我的项目及其下方的文件夹结构中,我可以在cordova.js
下找到Platforms/browser/www
。
但是,当我运行上面的第二个comman时,会打开一个空白的chrome浏览器实例(虽然我的默认设置是IE),并且在没有显示应用程序的情况下保持空白。下面是终端的堆栈跟踪。
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)
我在index.html
中加入了<script src="cordova.js"></script>
以下是我宣布Cordova的ts文件: 的数据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()在 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"
。但不确定这里的问题。有人可以帮助我,我在这里被打了一会儿。
答案 0 :(得分:0)
你指的是使用Ionic的链接我猜。请尝试以下步骤。
npm install -g ionic@latest
ionic serve
以在浏览器中运行。npm install -g cordova
答案 1 :(得分:0)
com.salesforce.plugin 不支持浏览器。它仅支持移动平台(即Android和iOS)。