代码之家  ›  专栏  ›  技术社区  ›  exequielc

未捕获SyntaxError:存在async/await时出现意外标识符

  •  1
  • exequielc  · 技术社区  · 6 年前

    当我在安卓6或7和安卓Oreo(8.1)上运行应用程序时,我遇到了这个错误

     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
    

    复制步骤

    相关代码

    async revisa_sincro(){<。。。。。代码…>}

    预期行为

    所以,真正的问题是这个[async]关键字停止应用程序,并向我显示白色屏幕和 如果我删除所有异步代码,应用程序运行正常。但我真的需要这个异步!!!

    离子信息

        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
    

      {
      "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"
        ]
      }
    }
    

    更新:

    {
      "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
      }
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Fenton    6 年前

    有两件事需要检查。。。

    ECMAScript版本

    您可以使用TypeScript编译器以不同的ECMAScript版本为目标,因此请确保以运行时使用的版本为目标。i、 e.在tsconfig.json文件中:

    "target": "ES5"
    

    如果您已经完成了上述操作,但仍然存在问题,那么这通常是由加载TypeScript文件引起的 .ts 这是运行时的意外,而不是JavaScript .js