android - 未捕获的 SyntaxError:存在 async/await 时出现意外标识符
问题描述
当我在 Android 6 或 7 和 android Oreo (8.1) 上运行应用程序时出现此错误
这是 logcat 在控制台中显示的错误
1-23 10:02:18.208 24346-24346/chess.pidoweb I/chromium: [INFO:CONSOLE(10)] "The key "viewport-fit" is not recognized and ignored.", source: file:///android_asset/www/index.html (10)
11-23 10:02:18.644 24346-24354/? I/zygote64: Ignoring second debugger -- accepting and dropping
11-23 10:02:18.880 24346-24428/? W/chromium: [WARNING:sqlite_persistent_cookie_store.cc(851)] Cookie database is too new.
11-23 10:02:18.881 24346-24428/? W/chromium: [WARNING:sqlite_persistent_cookie_store.cc(851)] Cookie database is too new.
11-23 10:02:23.006 24346-24364/? V/FA: Inactivity, disconnecting from the service
11-23 10:02:24.519 24346-24346/? I/chromium: [INFO:CONSOLE(588)] **"Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/www/build/main.js (588)**
11-23 10:02:24.546 24346-24346/? D/XWalkCordovaUiClient: onPageLoadStopped(file:///android_asset/www/index.html)
11-23 10:02:24.546 24346-24346/? D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
11-23 10:02:26.572 24346-24346/? W/zygote64: Attempt to remove non-JNI local reference, dumping thread
重现步骤
在设备 android 上运行项目 [Android APi 23 到 27 遇到同样的问题] 使用命令 ->ionic cordova run android
相关代码
[588] 行是 this-> async revisa_sincro() { < .....code....> }
预期行为
所以,真正的问题是这个 [async] 关键字会停止应用程序并显示白屏以及控制台上的这个错误 Uncaught SyntaxError。如果我删除每个异步代码,应用程序运行正常。但我真的需要这个异步!
附加上下文 我无法解决这个问题,有什么解决方法吗?
离子信息
Ionic:
ionic (Ionic CLI) : 4.0.0 (C:\Users\exe\AppData\Roaming\nvm\v8.11.2\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 7.1.2
System:
NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)
npm : 5.6.0
OS : Windows 10
Packaje.json
{
"name": "pidoionic",
"version": "0.0.10",
"description": "",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"config": {
"ionic_webpack": "config/webpack.config.js"
},
"dependencies": {
"@agm/core": "^1.0.0-beta.3",
"@angular/animations": "7.1.0",
"@angular/common": "7.1.0",
"@angular/core": "7.1.0",
"@angular/forms": "7.1.0",
"@angular/http": "7.1.0",
"@angular/platform-browser": "7.1.0",
"@angular/platform-browser-dynamic": "7.1.0",
"@angular/router": "7.1.0",
"@ionic-native/app-version": "4.17.0",
"@ionic-native/camera": "4.17.0",
"@ionic-native/core": "4.17.0",
"@ionic-native/device": "4.17.0",
"@ionic-native/fcm": "^4.17.0",
"@ionic-native/file": "^4.7.0",
"@ionic-native/firebase": "^4.17.0",
"@ionic-native/google-analytics": "4.17.0",
"@ionic-native/google-plus": "4.17.0",
"@ionic-native/image-resizer": "4.17.0",
"@ionic-native/local-notifications": "^4.17.0",
"@ionic-native/native-storage": "^4.17.0",
"@ionic-native/splash-screen": "~4.17.0",
"@ionic-native/sqlite": "^4.17.0",
"@ionic-native/sqlite-porter": "^4.17.0",
"@ionic-native/status-bar": "4.17.0",
"@ionic-native/unique-device-id": "^4.17.0",
"@ionic-native/youtube-video-player": "4.17.0",
"@ionic/pro": "2.0.3",
"@ionic/storage": "2.1.3",
"@ngx-translate/core": "10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"@types/google-maps": "^3.2.0",
"angular2-uuid": "^1.1.1",
"angularfire2": "^5.1.0",
"cordova": "^8.0.0",
"cordova-android": "7.1.2",
"cordova-android-support-gradle-release": "^1.4.4",
"cordova-browser": "5.0.3",
"cordova-ios": "4.5.5",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-camera": "^4.0.3",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-console": "^1.1.0",
"cordova-plugin-ionic-webview": "2.2.5",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-geolocation": "^2.4.3",
"cordova-plugin-googleplus": "~5.3.2",
"cordova-plugin-local-notification": "^0.9.0-beta.2",
"cordova-plugin-media": "^5.0.2",
"cordova-plugin-nativestorage": "^2.3.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-uniquedeviceid": "^1.3.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-plugin-youtube-video-player": "^2.0.0",
"cordova-sqlite-storage": "^2.5.1",
"firebase": "^5.5.9",
"global": "^4.3.2",
"imagemin": "^5.3.1",
"info.protonet.imageresizer": "^0.1.1",
"ionic": "^3.20.1",
"ionic-angular": "3.9.2",
"ionic-tooltips": "^2.1.1",
"ionicons": "4.2.6",
"jquery": "^3.3.1",
"local-storage": "^1.4.2",
"moment": "^1.7.2",
"ng-lottie": "^0.3.2",
"ng2-reactive-forms-validators": "^1.1.0",
"promise-polyfill": "8.1.0",
"q": "^1.5.1",
"run": "1.4.0",
"rxjs": "^6.3.2",
"rxjs-compat": "^6.3.2",
"sqlite3": "^4.0.0",
"sw-toolbox": "3.6.0",
"typeorm": "0.2.8",
"zone.js": "0.8.26"
},
"devDependencies": {
"@angular/cli": "7.0.6",
"@angular/compiler": "7.1.0",
"@angular/compiler-cli": "7.1.0",
"@ionic/app-scripts": "3.2.0",
"@types/google.analytics": "0.0.39",
"@types/googlemaps": "^3.30.11",
"@types/node": "^10.5.4",
"sql.js": "^0.5.0",
"ts-node": "7.0.0",
"typescript": "3.1.6"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-device",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-splashscreen"
],
"cordovaPlatforms": [],
"cordova": {
"plugins": {
"cordova-sqlite-storage": {},
"cordova-plugin-geolocation": {
"GEOLOCATION_USAGE_DESCRIPTION": " "
},
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"info.protonet.imageresizer": {},
"cordova-plugin-camera": {},
"cordova-plugin-googleplus": {
"REVERSED_CLIENT_ID": "com.googleusercontent.apps.781145103219-a87b3bd7d7858i8lrr2531nm8ml2bj6c",
"WEB_APPLICATION_CLIENT_ID": "781145103219-vn75hrm8tv0b54hkck4dokv5nnr0pvao.apps.ioniusercontent.com"
},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-uniquedeviceid": {},
"cordova-plugin-app-version": {},
"cordova-plugin-nativestorage": {},
"cordova-plugin-file": {},
"cordova-plugin-youtube-video-player": {},
"cordova-plugin-local-notification": {},
"cordova-android-support-gradle-release": {
"ANDROID_SUPPORT_VERSION": "27.+"
}
},
"platforms": [
"browser",
"ios",
"android"
]
}
}
更新: tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"lib": [
"dom",
"es2017"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"target": "ES2017",
"types" : ["node"],
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts",
"src/**/__tests__/*.ts"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
解决方案
有两件事要检查...
ECMAScript 版本
您可以使用 TypeScript 编译器针对不同的 ECMAScript 版本,因此请确保您针对的是您在运行时使用的版本。即在您的 tsconfig.json 文件中:
"target": "ES5"
然后,这会将您的 async/await 转换为该运行时可用的格式。
JavaScript
如果你做了上面的操作还是有问题,一般是因为.ts
运行时不小心加载了 TypeScript 文件,而不是 JavaScript.js
文件。
推荐阅读
- python-3.x - 日期时间模块的准确性
- java - 我无法在 Mysql Workbench 中设置数据类型
- c++ - MFC 使用指针数组的正确方法?
- python - Unhashable 类型:使用 GridSearchCV 进行 KNN 超参数调整时出现“numpy.ndarray”错误
- c - C 中的预处理器指令
- python - 如何在 discord.py 中捕获错误并发送响应?
- intellij-idea - 如何使嵌入式 Kafka 规则不显示两个测试产生的数据
- c - C编程中的分段错误错误
- python - 如何将元组应用于我的代码,以便获得输出“{('a', 'x'))”?
- javascript - 带有 axios 的 es6 异步模块 - ReferenceError: 未定义要求