将我们的Ionic应用程序部署到为浏览器平台编译的服务器后,我一直遇到问题,在该服务器上,所有发送到服务器的请求都失败了,并且用户无法使用它。仅当用户在部署时打开了网站,并且当用户重新加载页面时,网站才消失。
我尝试了许多可能的解决方案,但是没有运气,所以我将其发布在这里,希望能找到一些帮助。
我得到的控制台错误如下:
errorUncaught (in promise): NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. Error: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. at /platforms/browser/www/build/vendor.js?v=1540203735513:1:1007099 at t.invoke /platforms/browser/www/build/polyfills.js?v=1540203735513:3:14976) at Object.onInvoke ...
Uncaught (in promise): SecurityError: The operation is insecure. openDatabase@[native code] https://[domain.com]/build/vendor.js?v=1536911308754:1:1006552 t@https://[domain.com]/build/polyfills.js?v=1536911308754:3:21507 ...
如前所述,只有在以下情况下运行部署脚本(见下文)后,我才会收到这些错误:
例如:
# remove the browser platform
ionic cordova platform remove browser
# add the browser platform
ionic cordova platform add browser
# build with production mode
MY_ENV=staging ionic cordova build browser --prod --release
# deploy to the server
rsync -r platforms/browser/www/* cloud@[SERVER_IP]:/home/cloud/www/
注意。后来,我构建了一个更复杂的部署过程来尝试调试问题,但结果是相同的。
我的猜测是,原因可能与访问新页面时浏览器中的ionic的某些内部工作有关,它具有先前部署中具有某种ID的引用,然后进行查找,然后失败,因为新的部署版本更改了该ID。 API并未更改,因此端点不是问题。
要添加一些额外的上下文,以下是我们使用webpack和上面的部署脚本中使用的MY_ENV变量管理环境的方式;以及项目中软件包的版本。
环境管理
var path = require('path');
var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');
module.exports = function () {
var env = process.env.MY_ENV || process.env.IONIC_ENV;
var environmentsMapping = {
dev_docker: 'dev',
test: 'dev',
test_local: 'dev',
staging: 'prod',
qa: 'prod'
}
if (env !== 'prod' && env !== 'dev') {
// Default to dev config
useDefaultConfig[env] = useDefaultConfig[ environmentsMapping[env] ];
}
useDefaultConfig[env].resolve.alias = {
"@environment": path.resolve(__dirname + '/../../src/config/config.' + env + '.ts'),
};
return useDefaultConfig;
};
包裹
"dependencies": {
"@angular/common": "5.0.0",
"@angular/compiler": "5.0.0",
"@angular/compiler-cli": "5.0.0",
"@angular/core": "5.0.0",
"@angular/forms": "5.0.0",
"@angular/http": "5.0.0",
"@angular/platform-browser": "5.0.0",
"@angular/platform-browser-dynamic": "5.0.0",
"@ionic-native/app-version": "^4.11.0",
"@ionic-native/core": "4.3.2",
"@ionic-native/geolocation": "^4.15.0",
"@ionic-native/native-geocoder": "^4.15.0",
"@ionic-native/splash-screen": "4.3.2",
"@ionic-native/status-bar": "4.3.2",
"@ionic/storage": "^2.1.3",
"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^2.0.1",
"analytics-node": "^3.3.0",
"brmasker-ionic-3": "^1.0.9",
"cordova-android": "7.0.0",
"cordova-browser": "5.0.3",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-nativegeocoder": "^3.1.2",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-whitelist": "^1.3.1",
"cordova-sqlite-storage": "^2.3.1",
"flag-icon-css": "^3.0.0",
"ionic-angular": "3.9.2",
"ionic-plugin-keyboard": "^2.2.1",
"ionic2-rating": "^1.2.2",
"ionicons": "3.0.0",
"jquery": "^3.3.1",
"lodash": "^4.17.5",
"moment": "^2.21.0",
"ng-select": "^1.0.0-rc.5",
"ngx-bootstrap": "^2.0.5",
"ngx-credit-cards": "^1.0.9",
"raven-js": "^3.26.4",
"rxjs": "5.5.2",
"slick-carousel": "^1.8.1",
"sw-toolbox": "3.6.0",
"zone.js": "^0.8.21"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.0",
"@ionic/cli-plugin-cordova": "1.6.2",
"@types/jasmine": "^2.8.7",
"@types/node": "^10.1.2",
"angular2-template-loader": "^0.6.2",
"html-loader": "^0.5.5",
"ionic": "3.20.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.0",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"null-loader": "^0.1.1",
"postcss": "6.0.14",
"protractor": "^5.3.2",
"ts-loader": "^3.5.0",
"ts-node": "^6.0.3",
"typescript": "2.4.2",
"ws": "3.3.2"
}